Mother of Dragons trading strategy…
Forums › ProRealTime English forum › ProOrder support › Mother of Dragons trading strategy…
- This topic has 522 replies, 50 voices, and was last updated 3 years ago by LaurentBZH35.
-
-
10/27/2020 at 8:36 AM #148620
The backtests seem fine to me but could be an issue with positionsize. Minimum for demo is 1, minimum live is .5
10/27/2020 at 9:54 AM #148633But didn’t obtain same variables as you
Probably because mine is optimized with 200k of data. But also, I don’t necessarily choose variables for max profit, sometimes I think it’s better to go for a higher %win esp if it gives higher number of trades. Sometimes it’s based on VRT results.
As for adapting to other instruments, you really just have to go through all the variables for each timeframe top to bottom. You’ll have to do this 2 or 3 times as one change effects another. I have tried versions for DAX, CAC, SP500, FTSE, ASX – cant remember what else. Some of them are still limping along in demo but the DJ and NAS are the only ones I have faith in. If anything else might work, I would start with the DAX and try to bang that into shape, using DJ v5 as a template.
10/27/2020 at 10:51 AM #148640@nonetheless It is the same time as in Spain that comes in “NAS 5m MoD v4S” On November 1 the time changes in the US and then it will be necessary to put if not onmarket or (time <= 153000 – USDLS and time> = 220000 – USDLS) and it keeps giving me the same failure with the MM activated and I have 1 lotti in demo. Doesn’t it give you an error?
123456789101112once longStep = 0once openStrongShort = 0if not onmarket or (time <= 143000 - USDLS and time >= 210000 - USDLS) thenlongStep = 0openStrongShort = 0endif//detect strong direction for market openonce rangeOK = 50once tradeMin = 500IF (time >= 144000 - USDLS) AND (time <= 144000 + tradeMin - USDLS) THENopenStrongShort = close < open AND open - close > rangeOKENDIF10/27/2020 at 11:19 AM #148643It tests fine for me, both with or without MM. If the problem only occurs with MM you could try using a higher factor, like 5 0r 10, or try it with volpiemanuele’s MM
1 user thanked author for this post.
10/27/2020 at 1:07 PM #14865110/27/2020 at 1:24 PM #148653I really wouldn’t worry about it, any factor below 10 will give a result in the millions – it’s only something to dream about. But if factor 3 blows up over the past 100k then that can also happen over the coming 100k. I will change mine to 5; if the algo succeeds then positionsize will increase dramatically enough.
1 user thanked author for this post.
10/28/2020 at 5:18 AM #148740@volpiemanuele @nonetheless (ps. still searching for you)
Can you think of any reason why MM v5 and V.5a would be giving me these blank results. I am literally using the code that you both posted.
DJI MOD v5 works perfectly (see attached). It’s really strange.
This is DJI v5a + MM
This is the identical code that you have posted.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338// Definition of code parametersDEFPARAM CumulateOrders = false // Cumulating positions deactivatedDEFPARAM preloadbars = 5000//Money Management DOWMM = 1 // = 0 for optimizationif mm = 1 thenprof = 0ddpp = 212// max dd per pointddm = 2 // multiples of max drawdowns to factor into positionsizecapital = 350 //starting bankdpct = 5 //% margin for depositdeposit = (open/100)*dpct //margin per pointpri = 1 // percent to reinvest as a decimalpositionsize = (capital +((strategyprofit + prof)*pri))/((ddm*ddpp)+deposit)if positionsize < 0.25 thenpositionsize = 0.2endifelseonce positionsize = 0.2endifTIMEFRAME(2 hours,updateonclose)Period= 495inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)HULLa = weightedaverage[round(sqrt(Period))](inner)c1 = HULLa > HULLa[1]c2 = HULLa < HULLa[1]indicator1 = SuperTrend[8,4]c3 = (close > indicator1)c4 = (close < indicator1)ma = average[60,3](close)c11 = ma > ma[1]c12 = ma < ma[1]//Stochastic RSI | indicatorlengthRSI = 15 //RSI periodlengthStoch = 9 //Stochastic periodsmoothK = 10 //Smooth signal of stochastic RSIsmoothD = 5 //Smooth signal of smoothed stochastic RSImyRSI = RSI[lengthRSI](close)MinRSI = lowest[lengthStoch](myrsi)MaxRSI = highest[lengthStoch](myrsi)StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)K = average[smoothK](stochrsi)*100D = average[smoothD](K)c13 = K>Dc14 = K<DTIMEFRAME(30 minutes,updateonclose)indicator5 = Average[2](typicalPrice)indicator6 = Average[7](typicalPrice)c15 = (indicator5 > indicator6)c16 = (indicator5 < indicator6)TIMEFRAME(15 minutes,updateonclose)indicator2 = Average[4](typicalPrice)indicator3 = Average[8](typicalPrice)c7 = (indicator2 > indicator3)c8 = (indicator2 < indicator3)Periodc= 22innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)HULLc = weightedaverage[round(sqrt(Periodc))](innerc)c9 = HULLc > HULLc[1]c10 = HULLc < HULLc[1]TIMEFRAME(10 minutes)indicator4 = SuperTrend[2,6]indicator4a = SAR[0.025,0.025,0.1]c19 = (close > indicator4) or (close > indicator4a)c20 = (close < indicator4) or (close < indicator4a)TIMEFRAME(5 minutes)//Stochastic RSI | indicatorlengthRSIa = 3 //RSI periodlengthStocha = 6 //Stochastic periodsmoothKa = 9 //Smooth signal of stochastic RSIsmoothDa = 3 //Smooth signal of smoothed stochastic RSImyRSIa = RSI[lengthRSIa](close)MinRSIa = lowest[lengthStocha](myrsia)MaxRSIa = highest[lengthStocha](myrsia)StochRSIa = (myRSIa-MinRSIa) / (MaxRSIa-MinRSIa)Ka = average[smoothKa](stochrsia)*100Da = average[smoothDa](Ka)c23 = Ka>Dac24 = Ka<Dama3 = average[15,3](typicalPrice)c21 = ma3 > ma3[1]c22 = ma3 < ma3[1]Periodb= 15innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)HULLb = weightedaverage[round(sqrt(Periodb))](innerb)c5 = HULLb > HULLb[1]and HULLb[1]<HULLb[2]c6 = HULLb < HULLb[1]and HULLb[1]>HULLb[2]// Conditions to enter long positionsIF dhigh(0)-high<300 and c1 AND C3 AND C5 and c7 and c9 and c11 and c13 and c15 and c19 and c21 and c23 THENBUY positionsize CONTRACT AT MARKETSET STOP %LOSS 1.5SET TARGET %PROFIT 2.5ENDIF// Conditions to enter short positionsIF low-dlow(0)<600 and c2 AND C4 AND C6 and c8 and c10 and c12 and c14 and c16 and c20 and c22 and c24 THENSELLSHORT positionsize CONTRACT AT MARKETSET STOP %LOSS 2SET TARGET %PROFIT 2.2ENDIF//================== exit in profitif longonmarket and C6 and c8 and close>positionprice thensell at marketendifIf shortonmarket and C5 and c7 and close<positionprice thenexitshort at marketendif//==============exit at lossif longonmarket AND c2 and c6 and close<positionprice thensell at marketendifIf shortonmarket and c1 and c5 and close>positionprice thenexitshort at marketendif//%trailing stop functiononce trailingpercentlong = 0.21 // %once trailingpercentshort = 0.24 // %once accelerator = 0.05 // 1 = default; always > 0 (i.e. 0.5-3)once accelerator2 = 0.01 // 1 = default; always > 0 (i.e. 0.5-3)once ts2sensitivity = 2 // [0]close;[1]high/low;[2]low;high//====================once steppercentlong = (trailingpercentlong/10)*acceleratoronce steppercentshort = (trailingpercentshort/10)*accelerator2if onmarket thentrailingstartlong = tradeprice(1)*(trailingpercentlong/100)trailingstartshort = tradeprice(1)*(trailingpercentshort/100)trailingsteplong = tradeprice(1)*(steppercentlong/100)trailingstepshort = tradeprice(1)*(steppercentshort/100)endifif not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) thennewsl=0endifif ts2sensitivity=1 thents2sensitivitylong=hights2sensitivityshort=lowelsif ts2sensitivity=2 thents2sensitivitylong=lowts2sensitivityshort=highelsets2sensitivitylong=closets2sensitivityshort=closeendifif longonmarket thenif newsl=0 and ts2sensitivitylong-tradeprice(1)>=trailingstartlong thennewsl = tradeprice(1)+trailingsteplongendifif newsl>0 and ts2sensitivitylong-newsl>trailingsteplong thennewsl = newsl+trailingsteplongendifendifif shortonmarket thenif newsl=0 and tradeprice(1)-ts2sensitivityshort>=trailingstartshort thennewsl = tradeprice(1)-trailingstepshortendifif newsl>0 and newsl-ts2sensitivityshort>trailingstepshort thennewsl = newsl-trailingstepshortendifendifif barindex-tradeindex>1 thenif longonmarket thenif newsl>0 thensell at newsl stopendifif newsl>0 thenif low crosses under newsl thensell at marketendifendifendifif shortonmarket thenif newsl>0 thenexitshort at newsl stopendifif newsl>0 thenif high crosses over newsl thenexitshort at marketendifendifendifendif//************************************************************************IF longonmarket and barindex-tradeindex>1900 and close<positionprice thensell at marketendifIF shortonmarket and barindex-tradeindex>580 and close>positionprice thenexitshort at marketendif//=============================================if longonmarket and abs(open-close)<1 and high[1]>high and close>positionprice and high-close>13 thensell at marketendifif shortonmarket and abs(open-close)<1 and low[1]>low and close-low>9 and close<positionprice thenexitshort at marketendif//===================================myrsiM5=rsi[14](close)//if myrsiM5<20 and barindex-tradeindex>1 and longonmarket and close>positionprice thensell at marketendifif myrsiM5>70 and barindex-tradeindex>1 and shortonmarket and close<positionprice thenexitshort at marketendif// --------- US DAY LIGHT SAVINGS MONTHS ---------------- //mar = month = 3 // MONTH STARTnov = month = 11 // MONTH ENDIF (month > 3 AND month < 11) OR (mar AND day>14) OR (mar AND day-dayofweek>7) OR (nov AND day<=dayofweek AND day<7) THENUSDLS=010000ELSEUSDLS=0ENDIFonce shortStep = 0once longStep = 0once openStrongLong = 0once openStrongShort = 0if not onmarket or (time <= 143000 - USDLS and time >= 210000 - USDLS) thenshortStep = 0longStep = 0openStrongLong = 0openStrongShort = 0endif//detect strong direction for market openonce rangeOK = 45once tradeMin = 500IF (time >= 144000 - USDLS) AND (time <= 144000 + tradeMin - USDLS) THENopenStrongLong = close > open AND close - open > rangeOKopenStrongShort = close < open AND open - close > rangeOKENDIFonce bollperiod = 20once bollMAType = 1once s = 2once BollLevel = 90once BollSR = 50bollMA = average[bollperiod, bollMAType](close)STDDEV = STD[bollperiod]bollUP = bollMA + s * STDDEVbollDOWN = bollMA - s * STDDEVIF bollUP = bollDOWN THENbollPercent = 50ELSEbollPercent = 100 * (close - bollDOWN) / (bollUP - bollDOWN)ENDIF//Market spike upIF shortonmarket AND shortStep = 0 AND bollPercent > BollLevel THENshortStep = 1ENDIF//Market slowly come downIF shortonmarket AND shortStep = 1 AND bollPercent < 100 - BollLevel THENshortStep = 2ENDIF//Market still go back to bullish and supported after strong bull open, exitIF shortonmarket AND shortStep = 2 AND bollPercent > BollSR AND openStrongLong THENexitshort at marketENDIF//Market shoot downIF longonmarket AND longStep = 0 AND bollPercent < 100 - BollLevel THENlongStep = 1ENDIF//Market slowly go back upIF longonmarket AND longStep = 1 AND bollPercent > BollLevel THENlongStep = 2ENDIF//Market still go back to bearish and resisted after strong bear open, exitIF longonmarket AND longStep = 2 AND bollPercent < 100 - BollSR AND openStrongShort THENsell at marketENDIFonce trendPeriod = 70once trendPeriodResume = 30once trendGap = 3once trendResumeGap = 6if not onmarket thenfullySupported = 0fullyResisteded = 0endif//Market supported in the wrong directionIF shortonmarket AND fullySupported = 0 AND summation[trendPeriod](bollPercent > 50) >= trendPeriod - trendGap THENfullySupported = 1ENDIF//Market pull back but continue to be supportedIF shortonmarket AND fullySupported = 1 AND bollPercent[trendPeriodResume + 1] < 0 AND summation[trendPeriodResume](bollPercent > 50) >= trendPeriodResume - trendResumeGap THENexitshort at marketENDIF//Market resisted in wrong directionIF longonmarket AND fullyResisteded = 0 AND summation[trendPeriod](bollPercent < 50) >= trendPeriod - trendGap THENfullyResisteded = 1ENDIF//Market pull back but continue to be resistedIF longonmarket AND fullyResisteded = 1 AND bollPercent[trendPeriodResume + 1] > 100 AND summation[trendPeriodResume](bollPercent < 50) >= trendPeriodResume - trendResumeGap THENsell at marketENDIF//Started real wrong directiononce strongTrend = 70once strongPeriod = 6IF shortonmarket and openStrongLong and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent > strongTrend) = strongPeriod thenexitshort at marketENDIFIF longonmarket and openStrongShort and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent < 100 - strongTrend) = strongPeriod thensell at marketENDIFThis is DJI MOD v5a code that I am using:
DJI MOD v5a123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360// Definition of code parametersDEFPARAM CumulateOrders = false // Cumulating positions deactivatedDEFPARAM preloadbars = 5000//Money Management DOWMM = 1 // = 0 for optimizationif MM = 0 thenpositionsize=15ENDIFif MM = 1 thenONCE startpositionsize = .4ONCE factor = 5 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etcONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverageONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverageONCE tier1 = 55 // DOW €1 IG first tier margin limitONCE maxpositionsize = 550 // DOW €1 IG tier 2 margin limitONCE minpositionsize = .2 // enter minimum position allowedIF Not OnMarket THENpositionsize = startpositionsize + Strategyprofit/(factor*margin)ENDIFIF Not OnMarket THENIF startpositionsize + Strategyprofit/(factor*margin) > tier1 thenpositionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 marginENDIFIF Not OnMarket THENif startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THENpositionsize = minpositionsize //keeps positionsize from going below allowed minimumENDIFIF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize thenpositionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limitENDIFENDIFENDIFENDIFTIMEFRAME(2 hours,updateonclose)Period= 495inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)HULLa = weightedaverage[round(sqrt(Period))](inner)c1 = HULLa > HULLa[1]c2 = HULLa < HULLa[1]indicator1 = SuperTrend[8,4]c3 = (close > indicator1)c4 = (close < indicator1)ma = average[60,3](close)c11 = ma > ma[1]c12 = ma < ma[1]//Stochastic RSI | indicatorlengthRSI = 15 //RSI periodlengthStoch = 9 //Stochastic periodsmoothK = 10 //Smooth signal of stochastic RSIsmoothD = 5 //Smooth signal of smoothed stochastic RSImyRSI = RSI[lengthRSI](close)MinRSI = lowest[lengthStoch](myrsi)MaxRSI = highest[lengthStoch](myrsi)StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)K = average[smoothK](stochrsi)*100D = average[smoothD](K)c13 = K>Dc14 = K<DTIMEFRAME(30 minutes,updateonclose)indicator5 = Average[2](typicalPrice)indicator6 = Average[7](typicalPrice)c15 = (indicator5 > indicator6)c16 = (indicator5 < indicator6)TIMEFRAME(15 minutes,updateonclose)indicator2 = Average[4](typicalPrice)indicator3 = Average[8](typicalPrice)c7 = (indicator2 > indicator3)c8 = (indicator2 < indicator3)Periodc= 22innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)HULLc = weightedaverage[round(sqrt(Periodc))](innerc)c9 = HULLc > HULLc[1]c10 = HULLc < HULLc[1]TIMEFRAME(10 minutes)indicator4 = SuperTrend[2,6]indicator4a = SAR[0.025,0.025,0.1]c19 = (close > indicator4) or (close > indicator4a)c20 = (close < indicator4) or (close < indicator4a)TIMEFRAME(5 minutes)//Stochastic RSI | indicatorlengthRSIa = 3 //RSI periodlengthStocha = 6 //Stochastic periodsmoothKa = 9 //Smooth signal of stochastic RSIsmoothDa = 3 //Smooth signal of smoothed stochastic RSImyRSIa = RSI[lengthRSIa](close)MinRSIa = lowest[lengthStocha](myrsia)MaxRSIa = highest[lengthStocha](myrsia)StochRSIa = (myRSIa-MinRSIa) / (MaxRSIa-MinRSIa)Ka = average[smoothKa](stochrsia)*100Da = average[smoothDa](Ka)c23 = Ka>Dac24 = Ka<Dama3 = average[15,3](typicalPrice)c21 = ma3 > ma3[1]c22 = ma3 < ma3[1]Periodb= 15innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)HULLb = weightedaverage[round(sqrt(Periodb))](innerb)c5 = HULLb > HULLb[1]and HULLb[1]<HULLb[2]c6 = HULLb < HULLb[1]and HULLb[1]>HULLb[2]// Conditions to enter long positionsIF dhigh(0)-high<300 and c1 AND C3 AND C5 and c7 and c9 and c11 and c13 and c15 and c19 and c21 and c23 THENBUY positionsize CONTRACT AT MARKETSET STOP %LOSS 1.5SET TARGET %PROFIT 2.5ENDIF// Conditions to enter short positionsIF low-dlow(0)<600 and c2 AND C4 AND C6 and c8 and c10 and c12 and c14 and c16 and c20 and c22 and c24 THENSELLSHORT positionsize CONTRACT AT MARKETSET STOP %LOSS 2SET TARGET %PROFIT 2.2ENDIF//================== exit in profitif longonmarket and C6 and c8 and close>positionprice thensell at marketendifIf shortonmarket and C5 and c7 and close<positionprice thenexitshort at marketendif//==============exit at lossif longonmarket AND c2 and c6 and close<positionprice thensell at marketendifIf shortonmarket and c1 and c5 and close>positionprice thenexitshort at marketendif//%trailing stop functiontrailingpercentlong = 0.21 // %trailingpercentshort = 0.24 // %once acceleratorlong = 0.05 // [1] default; always > 0 (i.e. 0.5-3)once acceleratorshort= 0.01 // 1 = default; always > 0 (i.e. 0.5-3)ts2sensitivity = 3 // [1] default [2] hl [3] lh (not use once)//====================once steppercentlong = (trailingpercentlong/10)*acceleratorlongonce steppercentshort = (trailingpercentshort/10)*acceleratorshortif onmarket thentrailingstartlong = positionprice*(trailingpercentlong/100)trailingstartshort = positionprice*(trailingpercentshort/100)trailingsteplong = positionprice*(steppercentlong/100)trailingstepshort = positionprice*(steppercentshort/100)endifif not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) thennewsl = 0mypositionprice = 0endifpositioncount = abs(countofposition)if newsl > 0 thenif positioncount > positioncount[1] thenif longonmarket thennewsl = max(newsl,positionprice * newsl / mypositionprice)elsenewsl = min(newsl,positionprice * newsl / mypositionprice)endifendifendifif ts2sensitivity=1 thents2sensitivitylong=closets2sensitivityshort=closeelsif ts2sensitivity=2 thents2sensitivitylong=hights2sensitivityshort=lowelsif ts2sensitivity=3 thents2sensitivitylong=lowts2sensitivityshort=highendifif longonmarket thenif newsl=0 and ts2sensitivitylong-positionprice>=trailingstartlong*pipsize thennewsl = positionprice+trailingsteplong*pipsizeendifif newsl>0 and ts2sensitivitylong-newsl>=trailingsteplong*pipsize thennewsl = newsl+trailingsteplong*pipsizeendifendifif shortonmarket thenif newsl=0 and positionprice-ts2sensitivityshort>=trailingstartshort*pipsize thennewsl = positionprice-trailingstepshort*pipsizeendifif newsl>0 and newsl-ts2sensitivityshort>=trailingstepshort*pipsize thennewsl = newsl-trailingstepshort*pipsizeendifendifif barindex-tradeindex>1 thenif longonmarket thenif newsl>0 thensell at newsl stopendifif newsl>0 thenif low crosses under newsl thensell at marketendifendifendifif shortonmarket thenif newsl>0 thenexitshort at newsl stopendifif newsl>0 thenif high crosses over newsl thenexitshort at marketendifendifendifendifmypositionprice = positionprice//************************************************************************IF longonmarket and barindex-tradeindex>1900 and close<positionprice thensell at marketendifIF shortonmarket and barindex-tradeindex>580 and close>positionprice thenexitshort at marketendif//=============================================if longonmarket and abs(open-close)<1 and high[1]>high and close>positionprice and high-close>13 thensell at marketendifif shortonmarket and abs(open-close)<1 and low[1]>low and close-low>9 and close<positionprice thenexitshort at marketendif//===================================myrsiM5=rsi[14](close)//if myrsiM5<20 and barindex-tradeindex>1 and longonmarket and close>positionprice thensell at marketendifif myrsiM5>70 and barindex-tradeindex>1 and shortonmarket and close<positionprice thenexitshort at marketendif// --------- US DAY LIGHT SAVINGS MONTHS ---------------- //mar = month = 3 // MONTH STARTnov = month = 11 // MONTH ENDIF (month > 3 AND month < 11) OR (mar AND day>14) OR (mar AND day-dayofweek>7) OR (nov AND day<=dayofweek AND day<7) THENUSDLS=010000ELSEUSDLS=0ENDIFonce shortStep = 0once longStep = 0once openStrongLong = 0once openStrongShort = 0if not onmarket or (time <= 143000 - USDLS and time >= 210000 - USDLS) thenshortStep = 0longStep = 0openStrongLong = 0openStrongShort = 0endif//detect strong direction for market openonce rangeOK = 45once tradeMin = 500IF (time >= 144000 - USDLS) AND (time <= 144000 + tradeMin - USDLS) THENopenStrongLong = close > open AND close - open > rangeOKopenStrongShort = close < open AND open - close > rangeOKENDIFonce bollperiod = 20once bollMAType = 1once s = 2once BollLevel = 90once BollSR = 50bollMA = average[bollperiod, bollMAType](close)STDDEV = STD[bollperiod]bollUP = bollMA + s * STDDEVbollDOWN = bollMA - s * STDDEVIF bollUP = bollDOWN THENbollPercent = 50ELSEbollPercent = 100 * (close - bollDOWN) / (bollUP - bollDOWN)ENDIF//Market spike upIF shortonmarket AND shortStep = 0 AND bollPercent > BollLevel THENshortStep = 1ENDIF//Market slowly come downIF shortonmarket AND shortStep = 1 AND bollPercent < 100 - BollLevel THENshortStep = 2ENDIF//Market still go back to bullish and supported after strong bull open, exitIF shortonmarket AND shortStep = 2 AND bollPercent > BollSR AND openStrongLong THENexitshort at marketENDIF//Market shoot downIF longonmarket AND longStep = 0 AND bollPercent < 100 - BollLevel THENlongStep = 1ENDIF//Market slowly go back upIF longonmarket AND longStep = 1 AND bollPercent > BollLevel THENlongStep = 2ENDIF//Market still go back to bearish and resisted after strong bear open, exitIF longonmarket AND longStep = 2 AND bollPercent < 100 - BollSR AND openStrongShort THENsell at marketENDIFonce trendPeriod = 70once trendPeriodResume = 30once trendGap = 3once trendResumeGap = 6if not onmarket thenfullySupported = 0fullyResisteded = 0endif//Market supported in the wrong directionIF shortonmarket AND fullySupported = 0 AND summation[trendPeriod](bollPercent > 50) >= trendPeriod - trendGap THENfullySupported = 1ENDIF//Market pull back but continue to be supportedIF shortonmarket AND fullySupported = 1 AND bollPercent[trendPeriodResume + 1] < 0 AND summation[trendPeriodResume](bollPercent > 50) >= trendPeriodResume - trendResumeGap THENexitshort at marketENDIF//Market resisted in wrong directionIF longonmarket AND fullyResisteded = 0 AND summation[trendPeriod](bollPercent < 50) >= trendPeriod - trendGap THENfullyResisteded = 1ENDIF//Market pull back but continue to be resistedIF longonmarket AND fullyResisteded = 1 AND bollPercent[trendPeriodResume + 1] > 100 AND summation[trendPeriodResume](bollPercent < 50) >= trendPeriodResume - trendResumeGap THENsell at marketENDIF//Started real wrong directiononce strongTrend = 70once strongPeriod = 6IF shortonmarket and openStrongLong and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent > strongTrend) = strongPeriod thenexitshort at marketENDIFIF longonmarket and openStrongShort and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent < 100 - strongTrend) = strongPeriod thensell at marketENDIF10/28/2020 at 5:49 AM #148744@nonetheless – I just realized that in v5a you have MM switched on for some reason?
That’s what seems to be breaking it for me. Is there any variables in MM that would be tied to the instrument or currency?
As soon as I switch MM off it works again, which would also explain why the MM version is not working.
5a version with MM switched on.123456789101112131415161718192021222324252627282930313233// Definition of code parametersDEFPARAM CumulateOrders = false // Cumulating positions deactivatedDEFPARAM preloadbars = 5000//Money Management DOWMM = 1 // = 0 for optimizationif MM = 0 thenpositionsize=1ENDIFif MM = 1 thenONCE startpositionsize = .4ONCE factor = 5 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etcONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverageONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverageONCE tier1 = 55 // DOW €1 IG first tier margin limitONCE maxpositionsize = 550 // DOW €1 IG tier 2 margin limitONCE minpositionsize = .2 // enter minimum position allowedIF Not OnMarket THENpositionsize = startpositionsize + Strategyprofit/(factor*margin)ENDIFIF Not OnMarket THENIF startpositionsize + Strategyprofit/(factor*margin) > tier1 thenpositionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 marginENDIFIF Not OnMarket THENif startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THENpositionsize = minpositionsize //keeps positionsize from going below allowed minimumENDIFIF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize thenpositionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limitENDIFENDIFENDIFENDIF1 user thanked author for this post.
10/28/2020 at 6:18 AM #14874512345678910111213141516171819202122MM = 0 // = 0 for optimizationif mm = 1 thenprof = 0ddpp = 212// max dd per pointddm = 2 // multiples of max drawdowns to factor into positionsizecapital = 350 //starting bankdpct = 5 //% margin for depositdeposit = (open/100)*dpct //margin per pointpri = 1 // percent to reinvest as a decimalpositionsize = (capital +((strategyprofit + prof)*pri))/((ddm*ddpp)+deposit)if positionsize < 0.25 thenpositionsize = 0.2endifendifif mm = 0 thenpositionsize = 0.2endif@StingeRe My code run ok in my PRT (demo or live version). Try to change MM inserting this code. If MM = 0 you have fixed position and if MM = 1 you have the MM. I see that your currency is AUD. You can insert the correct value in AUD in this variable “ddpp” and “capital”. My currency is EURO. Thanks
10/28/2020 at 6:21 AM #148746@SitngeRe…first change the value in AUD….for me the problem is this….the code is correct….
10/28/2020 at 10:36 AM #148766I just realized that in v5a you have MM switched on for some reason?
MM is entirely optional, for me it tests correctly both with or without. If yours wont run with MM=1 you can try altering the positionsize, the factor or both.
10/28/2020 at 2:00 PM #148783@nonetheless, I have some issues with the TS, it just adjusts to BE but does not follow the price forward to cover the open positions. Do you have any idea why? Thanks in advance!
10/28/2020 at 2:15 PM #148785Yeah, I just noticed that as well, I’ll look into it.
1 user thanked author for this post.
10/28/2020 at 10:25 PM #14883510/29/2020 at 6:01 AM #148850Thanks @nonetheless, I noticed this last night as well when I was forward testing 4.xx vs 5.
Interesting they both ended up taking similar profits in the end though.
Thanks kindly for the fix.
-
AuthorPosts
Find exclusive trading pro-tools on