DAX Mtf strategy using a custom trend indicator
Forums › ProRealTime English forum › ProOrder support › DAX Mtf strategy using a custom trend indicator
- This topic has 13 replies, 5 voices, and was last updated 2 years ago by Khaled.
-
-
01/25/2019 at 3:39 PM #89658
User @Alessio posted a custom indicator on the italian forum, to tell Trending from Ranging markets (https://www.prorealcode.com/topic/indicatore-per-laterale-laterale-inclinato-trend/).
I liked it and wanted to give it a try on DAX, 1-hour TF, with Nicolas’trailing stop code on the 20-second TF. I decided to embed the indicator in the strategy, instead of CALLing it.
The indicators returns 1 for ranging market, 2 for sloping ranges and 3 for trending markets. I decided to enter a position (based on the direction of each candle) whenever it rises from 2 to 3.
Performance seems rewarding:
Trending Markets1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677ONCE TP = 42 //42ONCE SL = 21 //21/////////////////////////////////////////////////////////////////////////////////TIMEFRAME (1 hour, updateonclose) //h1ONCE n = 5 //5ONCE punti = 5 //5ONCE mediamobile = 45 //45ONCE puntiinclinato = 15 //15ONCE x = punti * pipsizeMA50 = LinearRegression[mediamobile](close)MAhigh = highest[n](MA50)MAlow = lowest[n](MA50)MA50range = Mahigh - MAlowlaterale = MA50range <= xlateraleinclinato = MA50range>x and ma50range<puntiinclinato+xtrend = ma50range>lateraleinclinato+puntiinclinatoif laterale thenresult=1elsif lateraleinclinato thenresult=2elsif trend thenresult=3endif// --- LONG conditionsa1 = close > opena2 = (Result = 3) AND (Result > Result[1])// --- SHORT conditionsb1 = close < openb2 = (Result = 3) AND (Result > Result[1])/////////////////////////////////////////////////////////////////////////////////TIMEFRAME (default) //20 sec.// --- LONG tradesIF a1 AND a2 AND Not Onmarket THENBUY 1 CONTRACT AT MARKETENDIF// --- SHORT tradesIF b1 AND b2 AND Not Onmarket THENSELLSHORT 1 CONTRACT AT MARKETENDIF//SET TARGET pPROFIT TPSET STOP pLOSS SL//**************************************************************************//trailing stop functiontrailingstart = 10 //10 trailing will start @trailinstart points profittrailingstep = 3 //3 trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF5 users thanked author for this post.
02/08/2019 at 2:22 PM #9086301/04/2022 at 6:23 PM #184519Dear fellow traders,
First, thanks to robertogozzi for this very effective trailing stop. You can see from the screenshot very little difference between MFE and exit price.
I was impressed with the effectiveness of the indicator shared by Alessio on the Italian forum, so I called it “Da Vinci”. Thank you Alessio!
I’m stuck with an MTF issue. I’m testing this H1 System run on 5min chart, which I’m testing only on 2k for the example. I expect the signals to be taken on the 1 hour basis. However, some of the trades are taken outside of this rule. For example, on 4 Jan. 2022 at 12:15 the System took a Long trade, while there is no Signal on the H1 chart between 11 and 13 and the Signal is Short on the 5min chart.
Can you please help to fix this MTF issue?
Any suggestions how to this strategy? Your ideas or comments are welcome!
NQ H1M5 Da Vinci123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301DEFPARAM CUMULATEORDERS= FALSEDEFPARAM PreLoadBars = 2000//////////////////////////////////////////////////////////////////////////////////////////////////////////////////TIMEFRAME(60 MINUTES, UPDATEONCLOSE)//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Ehlers RMSflen = 8//5//9//8//40 //fast lengthslen = 21//26//21//60 //slow lengthif barindex>slen thena1= 5/flena2= 5/slenPB = (a1 - a2) * close + (a2*(1 - a1) - a1 * (1 - a2))* close[1] + ((1 - a1) + (1 - a2))*(PB[1])- (1 - a1)* (1 - a2)*(PB[2])RMSa = summation[50](PB*PB)RMSplus = sqrt(RMSa/50)RMSminus = -RMSplusendifIF PB > RMSminus and PB > PB[1] THENLongRMS=+1ENDIFIF PB < RMSplus and PB < PB[1] THENShortRMS=-1ENDIF//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// StochasticsStoK = Stochastic[8,1](close)StoD = Average[3](Stochastic[8,1](close))IF (StoK >= 20) and (StoK > StoD) and (StoK > StoK[1]) THENLongSto=+1ENDIFIF (StoK <= 80) and (StoK < StoD) and (StoK < StoK[1]) THENShortSto=-1ENDIF//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Vigor IndexPeriodRVI = 8 //5//12diffRVI = close - openind1RVI = (diffRVI + 2*diffRVI[1] + 2*diffRVI[2] + diffRVI[3]) / 6ind2RVI = (Range + 2*Range[1] + 2*Range[2] + Range[3]) / 6condRVI = Summation[periodRVI](ind2RVI)IF condRVI = 0 THENtemp = 0.0001ELSEtemp = condRVIENDIFRVI = Summation[periodRVI](ind1RVI) / tempRVIsig = (RVI + 2*RVI[1] + 2*RVI[2] + RVI[3]) / 6IF (RVI > RVI[1]) and (RVI > RVIsig) THENLongRVI=+1ENDIFIF (RVI < RVI[1]) and (RVI < RVIsig) THENShortRVI=-1ENDIF//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Moving Average CrossingPFast = 8//5PSlow = 21//13HullFast = HullAverage[PFast](close)HullSlow = HullAverage[PSlow](close)EndPFast = EndPointAverage[PFast](close)EndPSlow = EndPointAverage[PSlow](close)TSFast = TimeSeriesAverage[PFast](close)TSSlow = TimeSeriesAverage[PSlow](close)LRFast = LinearRegression[PFast](close)LRSlow = LinearRegression[PSlow](close)ZLEMAFast = ZLEMA[PFast](close)ZLEMASlow = ZLEMA[PSlow](close)iRSI = RSI[14](close)IF HullFast > HullSlow and iRSI > iRSI[1] THENLongMA1=1elsif HullFast < HullSlow and iRSI < iRSI[1] THENShortMA1=-1ENDIFIF EndPFast > EndPSlow and iRSI > iRSI[1] THENLongMA2=2elsif EndPFast < EndPSlow and iRSI < iRSI[1] THENShortMA2=-2ENDIFIF TSFast > TSSlow and iRSI > iRSI[1] THENLongMA3=3elsif TSFast < TSSlow and iRSI < iRSI[1] THENShortMA3=-3ENDIFIF LRFast > LRSlow and iRSI > iRSI[1] THENLongMA4=4elsif LRFast < LRSlow and iRSI < iRSI[1] THENShortMA4=-4ENDIFIF ZLEMAFast > ZLEMASlow and iRSI > iRSI[1] THENLongMA5=5elsif ZLEMAFast < ZLEMASlow and iRSI < iRSI[1] THENShortMA5=-5ENDIFIF LongMA1=1 OR LongMA2=2 OR LongMA3=3 OR LongMA4=4 OR LongMA5=5 THENLongMA=+1ENDIFIF ShortMA1=-1 OR ShortMA2=-2 OR ShortMA3=-3 OR ShortMA4=-4 OR ShortMA5=-5 THENShortMA=-1ENDIF//////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Da Vinci Trend DetectorPeriodRangelateral = 8//5MultiplierATR = 0.5Points = AverageTrueRange[14](close) * MultiplierATRInclinedPoints = 15MAPeriod = 50n = PeriodRangelateral //4 daxx = Points * pipsize //5 a 15 laterale daxMA50 = LinearRegression[MAPeriod](close) //da 20 a 60 triangolareMAhigh = highest[n](MA50)MAlow = lowest[n](MA50)MA50range = Mahigh - MAlowlaterale = MA50range <= xlateraleinclinato = MA50range>x and ma50range<InclinedPoints+xtrend = ma50range>lateraleinclinato+InclinedPointsif laterale thenResultDaVinci=1elsif lateraleinclinato thenResultDaVinci=2elsif trend thenResultDaVinci=3endifIF ResultDaVinci>=2 THEN //and (ResultDaVinci <> ResultDaVinci[1])TrendDaVinci=+1ENDIF// TSIPeriodTSIFast = 9PeriodTSISlow = 2 * PeriodTSIFastaTSI = (ExponentialAverage[PeriodTSIFast](ExponentialAverage[PeriodTSISlow](ROC[1](close))))bTSI = (ExponentialAverage[PeriodTSIFast](ExponentialAverage[PeriodTSISlow](ABS(ROC[1](close)))))TSI = 100 * (aTSI/bTSI)LongMAExit = HullAverage[PExitL](close)ShortMAExit = HullAverage[PExitS](close)//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ComboLongDaVinci=0ShortDaVinci=0IF LongRMS=+1 AND LongSto=+1 AND LongRVI=+1 AND LongMA=+1 AND TrendDaVinci=+1 AND (TSI>TSI[1]) AND (close>open and close>close[1] and close>open[1]) THENLongDaVinci=+1ENDIFIF ShortRMS=-1 AND ShortSto=-1 AND ShortRVI=-1 AND ShortMA=-1 AND TrendDaVinci=+1 AND (TSI<TSI[1]) AND (close<open and close<close[1] and close<open[1]) THENShortDaVinci=-1ENDIFIF LongDaVinci=+1 THENMySignal = LongDaVinciENDIFIF ShortDaVinci=-1 THENMySignal = ShortDaVinciENDIFx = MySignalIF MySignal = MySignal[1] THENx = 0ENDIF//////////////////////////////////////////////////////////////////////////////////////////////////////////////////TIMEFRAME(DEFAULT)//////////////////////////////////////////////////////////////////////////////////////////////////////////////////IF NOT LongOnMarket AND (x = 1) THENBUY 1 CONTRACTS AT MARKETendifif LongOnMarket and -(x = -1) thenSELL AT MARKETSELLSHORT 1 CONTRACTS AT MARKETENDIFIF NOT ShortOnMarket AND -(x = -1) THENSELLSHORT 1 CONTRACTS AT MARKETendifif ShortOnMarket and (x = 1) thenEXITSHORT AT MARKETBUY 1 CONTRACTS AT MARKETENDIF//TIMEFRAME(DEFAULT)If LongOnMarket AND (close crosses under LongMAExit OR -(x = -1)) THENSELL AT MARKETENDIFIF ShortOnMarket AND (close crosses over ShortMAExit OR (x = 1)) THENEXITSHORT AT MARKETENDIF///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// BREAKEAVEN ///////////once breakeaven = 1//0 //1 on - 0 off//StartBreakeven = 30//PointsToKeep = 5//reset the breakevenLevel when no trade are on marketif breakeaven>0 thenIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- end of BUY SIDE ---IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPENDIFendif//////////////////////////////////////////////////////////////////////////////////////////////////////////// Trailing Stop//------------------------------------------------------------------------------------IF Not OnMarket THEN//TrailStart = 10 //10 Start trailing profits from this point//BasePerCent = 0.100 //10.0% Profit to keep//StepSize = 6 //6 Pips chunks to increase Percentage//PerCentInc = 0.100 //10.0% PerCent increment after each StepSize chunkRoundTO = -0.5 //-0.5 rounds to Lower integer, +0.4 rounds to Higher integerPriceDistance = 4 * pipsize//8.9 minimun distance from current pricey1 = 0y2 = 0ProfitPerCent = BasePerCentELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN //LONGx1 = (close - tradeprice) / pipsize //convert price to pipsIF x1 >= TrailStart THEN //go ahead only if N+ pipsDiff1 = abs(TrailStart - x1)Chunks1 = max(0,round((Diff1 / StepSize) + RoundTO))ProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc))ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))y1 = max(x1 * ProfitPerCent, y1) //y = % of max profitENDIFELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN//SHORTx2 = (tradeprice - close) / pipsize //convert price to pipsIF x2 >= TrailStart THEN //go ahead only if N+ pipsDiff2 = abs(TrailStart - x2)Chunks2 = max(0,round((Diff2 / StepSize) + RoundTO))ProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc))ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))y2 = max(x2 * ProfitPerCent, y2) //y = % of max profitENDIFENDIFIF y1 THEN //Place pending STOP order when y>0SellPrice = Tradeprice + (y1 * pipsize) //convert pips to priceIF abs(close - SellPrice) > PriceDistance THENIF close >= SellPrice THENSELL AT SellPrice STOPELSESELL AT SellPrice LIMITENDIFELSESELL AT MarketENDIFENDIFIF y2 THEN //Place pending STOP order when y>0ExitPrice = Tradeprice - (y2 * pipsize) //convert pips to priceIF abs(close - ExitPrice) > PriceDistance THENIF close <= ExitPrice THENEXITSHORT AT ExitPrice STOPELSEEXITSHORT AT ExitPrice LIMITENDIFELSEEXITSHORT AT MarketENDIFENDIFSET STOP %LOSS 0.501/04/2022 at 6:43 PM #184524I expect the signals to be taken on the 1 hour basis
TIMEFRAME(DEFAULT) will read the signal from the TF you are running on (5 minute). You can either run it on 1 hour, or delete TIMEFRAME(DEFAULT)
1 user thanked author for this post.
01/04/2022 at 6:49 PM #184525A LONG signal occurred at the 11:00 candle, which closes at 11:59, so it is valid till 12:59.
A LONG trade was entered at 12:00 (as soon as the 11:00 candle closed) and, since it was exited quite soon, it entered another one according to the same signal.
1 user thanked author for this post.
01/04/2022 at 7:02 PM #184526Thank you robertogozzi and nonetheless!
Do you think of any filter I can add to avoid this or to improve the strategy overall?
01/04/2022 at 7:24 PM #18452901/04/2022 at 8:15 PM #184535Thank you phoentzs
I tried to limit to 1 trade per hour on H1/M1 TF, but results were not satisfactory.
I kept H1/M1 and optimized Trailing Stop, Stop Loss and Exit Strategy and I now have a reasonable outcome on 5k, R/R 2.28, Sharpe 1.2, Win Rate 69% and Net Gain/Drawdown = 6.4. Now, time to test on 100k and see.
01/04/2022 at 8:26 PM #18453901/04/2022 at 9:08 PM #18455101/04/2022 at 10:27 PM #18456501/04/2022 at 10:58 PM #184567I trade manually only Dow (usually directional and you can capture 50 to 100pts quickly), and I have one Algo on NQ (because usually volatile), which I tested in Demo mode for one year, it generated 500% with 1 lot and an SL of 140pts. I’m trying to write an Algo targeting moves of 200pts on Dow, but it requires large SL (200pts)… Lately, I found myself letting the NQ Algo take the trade, then manage the rest manually. The Algo does usually better than me: Psychology is key! The NQ Algo is extremly simple (39 lines), Stoch + MACD with a few filters.
01/05/2022 at 9:31 AM #184585Hello – thank you for posting this. What time zone are you running it on, as my results are negative when I run a backtest? I know I must be doing something wrong 🙂 Thank you
I am testing on an IG CFD demo account, UK time zone on the NASDAQ 5m time frame
01/05/2022 at 10:14 AM #184587The last screenshot is NQ, (k units, H1/1M TF, which is different from the code I posted above (H1/M5), But when I switched to H1M5, I adapted the SL, Trailing Stop, etc. I’m running under French time zone.
Please note the System above is meant to be an example, it’s not a finished, so please feel free to tweak it and let us know how you improved it.
-
AuthorPosts
Find exclusive trading pro-tools on