ProRealCode - Trading & Coding with ProRealTime™
This system is not mine (maybe someone here recognize it) i found it years ago think it was on prorealtime site
anyway this is the original code not optimized, the short side need improvements
maybe with changes and money management it can be something for the library?
DEFPARAM CumulateOrders=False
REM Acquisto
indicator1 = ExponentialAverage[20](close)
indicator2 = ExponentialAverage[50](close)
c1 = (indicator1 > indicator2[1])
indicator3 = AroonUp[14]
indicator4 = Aroondown[14]
c2 = (indicator3 CROSSES OVER indicator4)
indicator41 = Stochastic[14,3](close)
c41 = (indicator41 < 75)
indicator100 = close
indicator101 = Supertrend[2,10]
c100 = indicator100 > indicator101
IF c1 AND c2 AND c41 AND c100 THEN
BUY 1 contracts AT MARKET
ENDIF
REM Vendita
indicator5 = close
indicator6 = ExponentialAverage[20](close)
c4 = (indicator5 < indicator6[1])
indicator7 = AroonUp[14]
indicator8 = AroonDown[14]
c5 = (indicator7 < indicator8[1])
IF c4 AND c5 THEN
SELL AT MARKET
ENDIF
REM Vendita allo scoperto
indicator9 = ExponentialAverage[20](close)
indicator10 = ExponentialAverage[50](close)
c6 = (indicator9 < indicator10[1])
indicator11 = AroonUp[14]
indicator12 = Aroondown[14]
c7 = (indicator12 CROSSES OVER indicator11)
indicator43 = Stochastic[14,3](close)
c43 = (indicator43 > 25)
indicator110 = close
indicator111 = Supertrend[2,10]
c110 = indicator111 > indicator110
IF c6 AND c7 AND c43 AND c110 THEN
SELLSHORT 1 contracts AT MARKET
ENDIF
REM Riacquisto
indicator13 = close
indicator14 = ExponentialAverage[20](close)
c9 = (indicator13 > indicator14[1])
indicator15 = AroonUp[14]
indicator16 = AroonDown[14]
c10 = (indicator15 > indicator16[1])
IF c9 AND c10 THEN
EXITSHORT AT MARKET
ENDIF
I have used a version live long only and removed stochastic and used a stoploss
maybe with some kind of trailing stop it would perform better?
2015 was pretty good but 2016 some draw down pre trump
its not rocket science and get rich quick but its profitable
DEFPARAM CumulateOrders=False
REM Acquisto
indicator1 = ExponentialAverage[20](close)
indicator2 = ExponentialAverage[50](close)
c1 = (indicator1 > indicator2[1])
indicator3 = AroonUp[14]
indicator4 = Aroondown[14]
c2 = (indicator3 CROSSES OVER indicator4)
indicator100 = close
indicator101 = Supertrend[2,10]
c100 = indicator100 > indicator101
IF c1 AND c2 AND c100 THEN
BUY 1 CONTRACTs AT MARKET
ENDIF
REM Vendita
indicator5 = close
indicator6 = ExponentialAverage[20](close)
c4 = (indicator5 < indicator6[1])
indicator7 = AroonUp[14]
indicator8 = AroonDown[14]
c5 = (indicator7 < indicator8[1])
IF c4 AND c5 THEN
SELL AT MARKET
ENDIF
SET STOP PLOSS 100
Thanks Eric, but you did not mention timeframe and instrument?
I have used it on DAX
30 minute timeframe
I had a version (long only) with EMA 50 and EMA 90 also
indicator1 and indicator2
It performs better with a trailing stop as you mentioned. Starting October 2015 it has a positiv result on FTSE100 too (30 min). The trailing stop function is from Nicolas blogpost.
DEFPARAM CumulateOrders=False
REM Acquisto
indicator1 = ExponentialAverage[50](close)
indicator2 = ExponentialAverage[90](close)
c1 = (indicator1 > indicator2[1])
indicator3 = AroonUp[14]
indicator4 = Aroondown[14]
c2 = (indicator3 CROSSES OVER indicator4)
indicator100 = close
indicator101 = Supertrend[2,10]
c100 = indicator100 > indicator101
IF c1 AND c2 AND c100 THEN
BUY 1 CONTRACTs AT MARKET
ENDIF
SET STOP PLOSS 150
//trailing stop
trailingstop = 40
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
If anyone is interested, here’s the system with a Donchian stop loss.
DEFPARAM CumulateOrders=False
indicator1 = ExponentialAverage[50](close)
indicator2 = ExponentialAverage[90](close)
c1 = (indicator1 > indicator2[1])
indicator3 = AroonUp[14]
indicator4 = Aroondown[14]
c2 = (indicator3 CROSSES OVER indicator4)
indicator100 = close
indicator101 = Supertrend[2,10]
c100 = indicator100 > indicator101
IF c1 AND c2 AND c100 THEN
BUY 1 CONTRACTs AT MARKET
ENDIF
// DONCHIAN STOP
DC=70
e= Highest[DC](high)
f=Lowest[DC](low)
if longonmarket then
laststop = f[1]
endif
if shortonmarket then
laststop = e[1]
endif
if onmarket then
sell at laststop stop
exitshort at laststop stop
endif
//trailing stop
trailingstop = 50
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
endif
elsif optimization = (x) then
Soft time stop The soft time stop simply counts the total number of bars of in loss endured during the trade (not consecutive but total bars of loss) and once a threshold is reached, triggers a break even signal so that the trade will at least break even if/when given the chance. The variable to adjust is softTimeStopBars (0 for off else positive number for number of bars in loss to trigger)
Second chance Stop The second chance stop, if engaged, monitors for a trade going into profit, followed by losing x% of the maximum gain (typically 70-90% retracement towards original entry). If this occurs a trigger is set to exit the trade when the gain reaches or exceeds the highest high of that trade’s equity curve (a second chance). The variable scRetraceTrigger is used to set the percentage retrace before we grab a second chance exit. 0.5 = 50% retracement. 1 = 100% retracement. It can also be set to negative value for monitoring if it went into loss after first being profitable). scMinBarsInTrade suspends monitoring until the trade has been on for at least a given number of bars.
ATR based target (limit) Often times you want limit orders to be a proportion of the current market volatility (so that you don’t set them too far or too near). Set useATRTarget to 1 to engage the system. atrTargetMultiple determines the limit order target by multiple of atr[40]
ATR filter When ATR filter is engaged, no trades will be taken unless atr[40] is above the given threshold. This reduces the likelihood of weak setups.
// -- // -- // -- // -- // -- |
// // -- // -- // -- // -- // |
// == Aroon System DAX M30 == |
// -- // -- // -- // -- // -- |
// // -- // -- // -- // -- // |
// Aroon System
// Version 1.01
// Contributors:
// Eric @ prorealcode.com
// Victormork @ prorealcode.com
// Maz @ prorealcode.com
// --------------
// Modules:
// Variable set selection framework
// Optional donchian stop (useDonchianStop)
// Optional trailing stop (useTrailingStop)
// Optional soft time stop (softTimeStopBars > 0)
// Optional second chance Stop (useSecondChanceStop) [version 0.11 alpha]
// Optional ATR based target (useATRTarget)
// Optional ATR filter (useATRFilter)
// --------------
// Originally developed for DAX M30
DEFPARAM CumulateOrders = false
// -- Variable Selection --
once positionSize = 1
once optimization = 1
if optimization = 1 then // DAX M30 (June 2016 - Apr 2017)
useDonchianStop = 1 // Engage Donchian Stop? 0:no | 1: yes
useTrailingStop = 1 // Engage trailing stop? 0:no | 1: yes
trailingStop = 51 //50 // trailing stop distance
once tsLongDistance = trailingStop
once tsShortDistance= trailingStop
useATRTarget = 1 // Engage ATR Limit 0:no | 1: yes
atrTargetMultiple = 21 // Limit is x times current ATR[40]
useATRFilter = 1 // Engage ATR filter 0: no | 1: yes
atrThreshold = 15 // 11 // only trade if ATR is above x
useSecondChanceStop = 0 // Engage 2nd chance stop. 0: off | 1: on
scRetraceTrigger = 0.5 // 0.4 // % of max profit reduction to trigger
scMinBarsInTrade = 14 // 2 // min # bars before trigger
softTimeStopBars = 37 // 35 // 0: off | lower = higher hit rate
maShortPeriod = 50 // short term MA period
maLongPeriod = 90 // long term MA period
arroonPeriod = 14
once arroonUpPeriod = arroonPeriod
once arroonDnPeriod = arroonPeriod
stMultiplier = 2 // Super trend multiplier
stPeriods = 7 // 10 // Super trend period
donchianChPeriod = 61 //70
tradingTime = 1//(time >= 080000 and time < 163000)
elsif optimization = 2 then // DAX H1 (experimental)
useATRTarget = 0
atrTargetMultiple = 21
softTimeStopBars = 0
useATRFilter = 0
atrThreshold = 15
useSecondChanceStop = 0
//scRetraceTrigger = 0.5 // 0.4
//scMinBarsInTrade = 14 // 2
useDonchianStop = 1
useTrailingStop = 1
trailingStop = 45 // 48 //43
once tsLongDistance = trailingStop
once tsShortDistance = trailingStop
arroonPeriod = 14 // 15
once arroonUpPeriod = arroonPeriod
once arroonDnPeriod = arroonPeriod
stMultiplier = 3.5 // 3.75
stPeriods = 14 // 13
donchianChPeriod = 50 // 55 //70
maShortPeriod = 53
maLongPeriod = 90
tradingTime = 1 //(time >= 080000 and time < 163000)
endif
// -- Indicators -----
maShrt = exponentialAverage[maShortPeriod](close)
maLong = exponentialAverage[maLongPeriod](close)
arUp = aroonUp[arroonUpPeriod]
arDn = aroonDown[arroonDnPeriod]
sTrend = supertrend[stMultiplier, stPeriods]
atr = averageTrueRange[40]
inProfit = onMarket and positionPerf > 0 // ignore for now
// -- Entry conditions -----
// - Long entry -
bc1 = not longOnMarket and tradingTime
bc1 = bc1 and (arUp CROSSES OVER arDn)
bc1 = bc1 and (maShrt > maLong[1]) and (close > sTrend)
bc1 = (bc1 and useATRFilter and atr > atrThreshold) or (bc1 and (not useATRFilter))
// -- Short entry conditions (AKA long exit) ----
sc1 = not ShortOnMarket
sc1 = sc1 and (arUp crosses under arDn)
sc1 = sc1 and (maShrt < maLong[1]) and (close < sTrend)
//sc1 = sc1 and (maLong < maLong[2])
// -- Donchian Stop Logic -----
if useDonchianStop and onMarket then
if longOnMarket then
dcLo = lowest[donchianChPeriod](low)
dcLastStop = dcLo[1]
sell at dcLastStop stop
elsif shortOnMarket then
dcHi = highest[donchianChPeriod](high)
dcLastStop = dcHi[1]
exitshort at dcLastStop stop
endif
endif
// -- Trailing Stop Logic -----
if useTrailingStop then
once tsLong = tsLongDistance * pointsize
once tsShort = tsShortDistance * pointsize
if (not onMarket) then
tsMaxPrice = 0
tsMinPrice = close
tsExitLevel = 0
elsif (onMarket and tsExitLevel > 0) then
exitShort at tsExitLevel stop
sell at tsExitLevel stop
elsif longOnMarket then
tsMaxPrice = max(tsMaxPrice,close)
if tsMaxPrice-tradeprice(1) >= tsLong then
tsExitLevel = tsMaxPrice - tsLong
endif
elsif shortOnMarket then
tsMinPrice = MIN(tsMinPrice,close)
if tradePrice(1)-tsMinPrice >= tsShort then
tsExitLevel = tsMinPrice + tsShort
endif
endif
endif
// -- ATR based target --
if onMarket and useATRTarget then
set target pProfit (atr * atrTargetMultiple) * pointSize
endif
// -- Soft Time Stop --
if onMarket and softTimeStopBars > 0 then
if not inProfit then
countLosingBars = countLosingBars + 1
endif
if countLosingBars >= softTimeStopBars and inProfit then
sc1 = 1 /// can exit
endif
elsif not onMarket and countLosingBars > 0 then
countLosingBars = 0
endif
// -- Second chance profit lock -----
if onMarket and useSecondChanceStop then
once scTriggered = 0
once maxPerf = 0
if scTriggered and positionPerf >= maxPerf then
sc1 = 1
else
maxPerf = max(maxPerf, positionPerf)
scTriggered = (barIndex - tradeIndex >= scMinBarsInTrade)
scTriggered = scTriggered and positionPerf <= (maxPerf * scRetraceTrigger)
endif
elsif useSecondChanceStop and (not onMarket) and maxPerf > 0 then
// Reset when off market
maxPerf = 0
scTriggered = 0
endif
// -- execution logic -----
if bc1 then
buy positionSize contracts at market
elsif sc1 then // and (not inProfit) then
if onmarket then
sell at market // exit long position if short setup triggerd
endif
//sellshort positionSize contracts at market
endif
DAX Aroon 30 min system
This topic contains 19 replies,
has 6 voices, and was last updated by Eric
8 years, 4 months ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 03/08/2017 |
| Status: | Active |
| Attachments: | 4 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.