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/01/2020 at 4:12 PM #146111
Ok.. I’ve had a similar issue on another instrument but had some values as low as 3 in the smoothK/smoothD variables. I increased them above 5 and optimised again, haven’t had an issue again yet but it does not fire as often as say the DJI algo. I’d be curious if you increase those to a min of 5 if you continue getting the same error.. I was suspecting that area to be my lines of code failing.. as obviously this can only occur in the code where a division is carried out where the denominator is getting quite small in comparison to the numerator… unless I have missed something elsewhere.
10/01/2020 at 5:10 PM #146117Brent but realized I had to scrap it because of constant zero division error.
Didn’t experience this before. Thanks for sharing.
@christofferrydberg, in any case, I suspect more on this few lines,123MinRSIa = lowest[lengthStocha](myrsia)MaxRSIa = highest[lengthStocha](myrsia)StochRSIa = (myRSIa-MinRSIa) / (MaxRSIa-MinRSIa)I noticed you set the lengthStocha to be 3. In case the market very low volatility, and RSI doesn’t move for 3 bars, then you might result a zero for MaxRSIa-MinRSIa
Maybe you can protect it by something like this,
12345678910111213myRSIa = RSI[lengthRSIa](close)MinRSIa = lowest[lengthStocha](myrsia)MaxRSIa = highest[lengthStocha](myrsia)IF MaxRSIa = MinRSIa THENc23 = 0c24 = 0ELSEStochRSIa = (myRSIa-MinRSIa) / (MaxRSIa-MinRSIa)Ka = average[smoothKa](stochrsia)*100Da = average[smoothDa](Ka)c23 = Ka>Dac24 = Ka<DaENDIFIf you really interested to confirm this issue, then you can check the time stamp when the issue is reported to you. Put the indicator on chart, then pay attention to the time stamp so it narrow down your debugging range.
If not above issue, you can still do the same for other division function, by doing a graph of the division.
2 users thanked author for this post.
10/07/2020 at 7:30 PM #146692My version of the system (little changed from the V4a I copied from here) took a long on 1/10/2020 at 12:00:01 and was stopped out for a big loss on 2/10/2020 at 05:55:58. Today I ran the backtest to look at something else and discovered that the backtest does not take this trade and I cannot see why. Even if I copy the code from the live system into a new system and run it it doesn’t take the trade no matter how much I change the spread value (can’t think what else could account for it). Anyone else had this happen?
10/09/2020 at 8:53 AM #146831Hi Autostrategist, yes, unfortunately I experienced the same (currently running version DJ 5m 4.7.2a).
Live entry on 1/10/20 12:00:00 and stop loss hit 2/10/20 05:55:56 (UK times). Doesn’t show up on my backtest.
I’ve been running a version of this since 29 March 2020 and usually real results are very similar to backtest (although 2-3 June and 20 and 24 Aug I found were less good replication). So not just you, but not sure why it happened! Very grateful though for the sharing of this code, as still in profit over that period, despite this 🙂
10/09/2020 at 9:48 AM #146838I added a rounding up for the order sizes, to full numbers, just in case someone has problems orders smaller than 1.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293///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 = 1ONCE 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 = 1 // enter minimum position allowedIF Not OnMarket THENpositionsize = round (startpositionsize + Strategyprofit/(factor*margin))//rounding upENDIFIF Not OnMarket THENIF startpositionsize + Strategyprofit/(factor*margin) > tier1 thenpositionsize = round((((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1) //incorporating tier 2 marginENDIFIF Not OnMarket THENif startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THENpositionsize = round (minpositionsize) //keeps positionsize from going below allowed minimumENDIFIF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize thenpositionsize = round (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,6]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= 23innerc = 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)indicator1a = SuperTrend[2,7]c19 = (close > indicator1a)c20 = (close < indicator1a)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](close)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<250 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.4ENDIF// Conditions to enter short positionsIF low-dlow(0)<700 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 1.5SET 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 functiontrailingPercent = .26stepPercent = .014if onmarket thentrailingstart = tradeprice(1)*(trailingpercent/100) //trailing will start @trailingstart points profittrailingstep = tradeprice(1)*(stepPercent/100) //% step to move the stoplossendif//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart THENnewSL = tradeprice(1)+trailingstepENDIF//next movesIF newSL>0 AND close-newSL>trailingstep THENnewSL = newSL+trailingstepENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart THENnewSL = tradeprice(1)-trailingstepENDIF//next movesIF newSL>0 AND newSL-close>trailingstep THENnewSL = newSL-trailingstepENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//************************************************************************IF longonmarket and barindex-tradeindex>1800 and close<positionprice thensell at marketendifIF shortonmarket and barindex-tradeindex>610 and close>positionprice thenexitshort at marketendif//=============================================if longonmarket and abs(open-close)<1 and high[1]>high and close>positionprice and high-close>10thensell at marketendifif shortonmarket and abs(open-close)<1 and low[1]>low and close-low>13 and close<positionprice thenexitshort at marketendif//===================================myrsiM5=rsi[14](close)//if myrsiM5<30 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 openStrongLong = 0once openStrongShort = 0if (time <= 223000 - USDLS and time >= 050000 - USDLS) thenopenStrongLong = 0openStrongShort = 0endif//detect strong direction for market openonce rangeOK = 40once tradeMin = 1500IF (time >= 223500 - USDLS) AND (time <= 223500 + tradeMin - USDLS) AND ABS(close - open) > rangeOK THENIF close > open and close > open[1] THENopenStrongLong = 1openStrongShort = 0ENDIFIF close < open and close < open[1] THENopenStrongLong = 0openStrongShort = 1ENDIFENDIFonce bollperiod = 20once bollMAType = 1once s = 2bollMA = average[bollperiod, bollMAType](close)STDDEV = STD[bollperiod]bollUP = bollMA + s * STDDEVbollDOWN = bollMA - s * STDDEVIF bollUP = bollDOWN THENbollPercent = 50ELSEbollPercent = 100 * (close - bollDOWN) / (bollUP - bollDOWN)ENDIFonce 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 = 60once strongPeriod = 8once strongTrendGap = 2IF shortonmarket and openStrongLong and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent > strongTrend) = strongPeriod - strongTrendGap thenexitshort at marketENDIFIF longonmarket and openStrongShort and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent < 100 - strongTrend) = strongPeriod - strongTrendGap thensell at marketENDIF1 user thanked author for this post.
10/12/2020 at 10:31 PM #147233I have tried to run Mother of dragons v4.5 live for a while. The only Changes I have made is my own optimization of the values. Time after time the algo is stopped because “division by zero”.
Is there a general way to eliminate that or how do a newbie in PRT coding proceed to fix this?
1 user thanked author for this post.
10/13/2020 at 6:30 PM #147339hi, which version do you suggest to me to trade in real ? I’m interested on NQ, DJ and DAX.
Thanks
10/18/2020 at 9:15 PM #147680@OboeOpt Might be stating the obvious but a division by zero error occurs when the variable to the right of the division operator i.e. ‘/’ is zero. Take this line from MOD code as an example (myRSIa–MinRSIa) / (MaxRSIa–MinRSIa), if ever the values to the right of the ‘/’ were to equal zero (not saying they can) then the error would occur. I have been running MOD and a DAX version for months without seeing this error. I have seen the error in the past with other systems and it is usually caused by a situation in the market that had not been accounted for like when the DJI was paused on limit up or down or a market is unusually quiet and fails to make one or more bars for a while etc. The only way to track it down is to work through all the possible divisions and see which one is causing the error.
1 user thanked author for this post.
10/18/2020 at 9:38 PM #147681Normally I can figure out why a trade was taken even though I wasn’t expecting it e.g. a difference in the spread from live Versus backtest or insufficient backtest data for the moving average but in this case I couldn’t work it out so I raised the issue with PRT, see below:
The referenced strategy took a long on 1/10/2020 at 12:00:01 and exited at a loss on 2/10/2020 at 05:55:58. The backtest does not take this trade and I cannot see why. Can you explain please.
Concerned strategy: (required) : DJ 5m Mother of Dragons v4.9 – Wall Street (DFB) – 28-Jun-2020 16:51:22To my amazement I got this response:
We have identified the problem you reported about your backtest and our technical team is currently working on a correction, which will be implemented as soon as possible. Please note that depending on the complexity of the correction needed, it may take up to several weeks for the problem to be corrected.
That errant trade cost me several hundred pounds but I don’t expect they will be compensating me 🙁 .
10/19/2020 at 8:39 PM #147797Mother of Dragons made in one week its 2 worst losses since Feb 2018. In both cases, it first closed one long position (in profit) and took again a long position a few minutes later.
Then this position would stay opened several hours / days until it hits stoploss. I was wondering whether it would be great to prevent the robot to open a new position if another one has been closed a few minutes ago.
What are your thoughts about that ?
1 user thanked author for this post.
10/20/2020 at 9:51 AM #147864You can use something like the below, I got this from one of the PRC gurus. It will force the strategy to wait N bars. However, the reality is that the returns are such that you sometimes just take the rough with the smooth, or you risk missing out on the next big move.
1234567891011//WaitONCE Count = 0ONCE MinCount = 5IF (Not OnMarket AND OnMarket[1]) OR (StrategyProfit <> StrategyProfit[1]) THEN //check thare was a trade open the previous bar and not any longer....Count = 1 //... to start counting periods (bars)ELSECount = Count + 1 //increment Count at each new period (bar)ENDIFIF OnMarket THENCount = 0ENDIF2 users thanked author for this post.
10/20/2020 at 7:25 PM #147956You can use something like the below, I got this from one of the PRC gurus. It will force the strategy to wait N bars. However, the reality is that the returns are such that you sometimes just take the rough with the smooth, or you risk missing out on the next big move.
1234567891011//WaitONCE Count = 0ONCE MinCount = 5IF (Not OnMarket AND OnMarket[1]) OR (StrategyProfit <> StrategyProfit[1]) THEN //check thare was a trade open the previous bar and not any longer….Count = 1 //… to start counting periods (bars)ELSECount = Count + 1 //increment Count at each new period (bar)ENDIFIF OnMarket THENCount = 0ENDIFThank you for your answer. I will look into it.
But I agree, with this code implemented, it could miss the next big move…
10/20/2020 at 8:23 PM #147962It’s worth noting, with elections in the US soon it’s worth de-risking for the next few weeks.
10/23/2020 at 9:17 AM #14815110/25/2020 at 10:50 AM #148388In PRT unlike some other programming languages if a variable is declared it has to be used, either use Mincount or comment it out/delete it.
-
AuthorPosts
Find exclusive trading pro-tools on