3 MAs PullBack DAX daily on MTF ???
Forums › ProRealTime English forum › ProOrder support › 3 MAs PullBack DAX daily on MTF ???
- This topic has 3 replies, 3 voices, and was last updated 6 years ago by Nicolas.
-
-
07/06/2018 at 6:12 PM #75493
I’ve been playing around with this code for some time and I am asking whether someone (not me at present, since IG customers will have MTF… I don’t know when) could test it with MTF enabled, so it can be tested on a 2-year data history, both for the Daily TF and the 5/10-minute TF using MTF for the sole TRAILING STOP code, to see if any improvements occur:
3 MAs Pullback DAX daily123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293//************************************************************************// 3 MAs Pullback DAX daily//// (Ema 10 + Ema 20 + Ema 120)//************************************************************************DEFPARAM CumulateOrders = FalseONCE nLots = 1ONCE LookBack = 3 //3 bars to set SL to the highest/lowestONCE Multiplier = 6 //6 times the Stop LossIF OnMarket THENCrossingUP = 0 //Reset flags to zero when...CrossingDN = 0 //... On MarketENDIFONCE AvgType = 6 //6 = Time SeriesFastMA = average[10,AvgType](close) //10SlowMA = average[20,AvgType](close) //20LongMA = average[120,AvgType](close) //120//////////////////////////////////////////////////////////////////////////////////////////////////////////// I don't care which order they are, it's important the highest MA is CROSSED OVER or// the lowest one is CROSSED UNDER//IF close CROSSES OVER Max(FastMA,Max(SlowMA,LongMA)) THENCrossingUP = 1CrossingDN = 0ENDIFIF close CROSSES UNDER Min(FastMA,Min(SlowMA,LongMA)) THENCrossingUP = 0CrossingDN = 1ENDIF//////////////////////////////////////////////////////////////////////////////////////////////////////////// Trailing Stop code// to be tested on a 5/10-minute TFONCE TrailStart = 50 //50 Start trailing profits from this pointONCE ProfitPerCent = 0.250 //25.0% Profit to keepIF Not OnMarket THENy1 = 0y2 = 0ELSIF LongOnMarket AND high > (TradePrice + (y1 * pipsize)) THEN //LONGx1 = (high - tradeprice) / pipsize //convert price to pipsIF x1 >= TrailStart THEN //go ahead only if TRAILSTART+ pipsy1 = max(x1 * ProfitPerCent, y1) //y = % of max profitENDIFIF y1 THENy1 = y1 * pipsize //convert pips to priceIF close < (TradePrice + y1) THEN //IF CLOSE < Tradeprice + Profit...SELL AT MARKET //... exit immediatelyELSESELL AT Tradeprice + y1 STOP //Place pending STOP order when y1>0ENDIFENDIFELSIF ShortOnMarket AND low < (TradePrice - (y2 * pipsize)) THEN //SHORTx2 = (tradeprice - low) / pipsize //convert price to pipsIF x2 >= TrailStart THEN //go ahead only if TRAILSTART+ pipsy2 = max(x2 * ProfitPerCent, y2) //y = % of max profitENDIFIF y2 THENy2 = y2 * pipsize //convert Pips to PriceIF (TradePrice + y2) > close THEN //IF Tradeprice + Profit > CLOSE ...EXITSHORT AT MARKET //... exit immediatelyELSEEXITSHORT AT Tradeprice - y2 STOP //Place pending STOP order when y2>0ENDIFENDIFENDIF////////////////////////////////////////////////////////////////////////////////////////////////////////////************************************************************************// LONG//************************************************************************a0 = CrossingUP //There must have been a CROSS OVERa1 = close[1] < Min(FastMA,SlowMA) //Previous bar must have closed < lowest among FastMA/SlowMAa2 = close CROSSES OVER Max(FastMA,SlowMA) //a CROSS OVER is occurring this bara3 = close > open //a bullish bar is mandatoryax = a0 AND a1 AND a2 AND a3IF ax AND Not OnMarket THENSl = ((close - lowest[LookBack](low)) / pipsize) //SL at the lowest low within LOOKBACK barsTp = Sl * MultiplierBUY nLots CONTRACT AT MARKETENDIF//************************************************************************// SHORT//************************************************************************b0 = CrossingDN //There must have been a CROSS UNDERb1 = close[1] > Max(FastMA,SlowMA) //Previous bar must have closed > lowest among FastMA/SlowMAb2 = close CROSSES UNDER Min(FastMA,SlowMA)//a CROSS OVER is occurring this barb3 = close < open //a bearish bar is mandatorybx = b0 AND b1 AND b2 AND b3IF bx AND Not Onmarket THENSl = ((highest[LookBack](high) - close) / pipsize) //SL at the highest high within LOOKBACK barsTp = Sl * MultiplierSELLSHORT nLots CONTRACT AT MARKETENDIFSET TARGET pPROFIT TpSET STOP pLOSS Sl07/06/2018 at 6:36 PM #7549407/06/2018 at 6:39 PM #7549707/07/2018 at 10:48 AM #75518I changed the code this way to be compatible with MTF: (trading entries are calculated with the daily chart, while trailing stop is made with the 5 minutes one)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101//************************************************************************// 3 MAs Pullback DAX daily//// (Ema 10 + Ema 20 + Ema 120)//************************************************************************DEFPARAM CumulateOrders = Falsetimeframe(daily,updateonclose)ONCE nLots = 1ONCE LookBack = 3 //3 bars to set SL to the highest/lowestONCE Multiplier = 6 //6 times the Stop LossIF OnMarket THENCrossingUP = 0 //Reset flags to zero when...CrossingDN = 0 //... On MarketENDIFONCE AvgType = 6 //6 = Time SeriesFastMA = average[10,AvgType](close) //10SlowMA = average[20,AvgType](close) //20LongMA = average[120,AvgType](close) //120//////////////////////////////////////////////////////////////////////////////////////////////////////////// I don't care which order they are, it's important the highest MA is CROSSED OVER or// the lowest one is CROSSED UNDER//IF close CROSSES OVER Max(FastMA,Max(SlowMA,LongMA)) THENCrossingUP = 1CrossingDN = 0ENDIFIF close CROSSES UNDER Min(FastMA,Min(SlowMA,LongMA)) THENCrossingUP = 0CrossingDN = 1ENDIF////////////////////////////////////////////////////////////////////////////////////////////////////////////************************************************************************// LONG//************************************************************************a0 = CrossingUP //There must have been a CROSS OVERa1 = close[1] < Min(FastMA,SlowMA) //Previous bar must have closed < lowest among FastMA/SlowMAa2 = close CROSSES OVER Max(FastMA,SlowMA) //a CROSS OVER is occurring this bara3 = close > open //a bullish bar is mandatoryax = a0 AND a1 AND a2 AND a3IF ax AND Not OnMarket THENSl = ((close - lowest[LookBack](low)) / pipsize) //SL at the lowest low within LOOKBACK barsTp = Sl * MultiplierBUY nLots CONTRACT AT MARKETENDIF//************************************************************************// SHORT//************************************************************************b0 = CrossingDN //There must have been a CROSS UNDERb1 = close[1] > Max(FastMA,SlowMA) //Previous bar must have closed > lowest among FastMA/SlowMAb2 = close CROSSES UNDER Min(FastMA,SlowMA)//a CROSS OVER is occurring this barb3 = close < open //a bearish bar is mandatorybx = b0 AND b1 AND b2 AND b3IF bx AND Not Onmarket THENSl = ((highest[LookBack](high) - close) / pipsize) //SL at the highest high within LOOKBACK barsTp = Sl * MultiplierSELLSHORT nLots CONTRACT AT MARKETENDIFSET TARGET pPROFIT TpSET STOP pLOSS Sltimeframe(default)//////////////////////////////////////////////////////////////////////////////////////////////////////////// Trailing Stop code// to be tested on a 5/10-minute TFONCE TrailStart = 50 //50 Start trailing profits from this pointONCE ProfitPerCent = 0.250 //25.0% Profit to keepIF Not OnMarket THENy1 = 0y2 = 0ELSIF LongOnMarket AND high > (TradePrice + (y1 * pipsize)) THEN //LONGx1 = (high - tradeprice) / pipsize //convert price to pipsIF x1 >= TrailStart THEN //go ahead only if TRAILSTART+ pipsy1 = max(x1 * ProfitPerCent, y1) //y = % of max profitENDIFIF y1 THENy1 = y1 * pipsize //convert pips to priceIF close < (TradePrice + y1) THEN //IF CLOSE < Tradeprice + Profit...SELL AT MARKET //... exit immediatelyELSESELL AT Tradeprice + y1 STOP //Place pending STOP order when y1>0ENDIFENDIFELSIF ShortOnMarket AND low < (TradePrice - (y2 * pipsize)) THEN //SHORTx2 = (tradeprice - low) / pipsize //convert price to pipsIF x2 >= TrailStart THEN //go ahead only if TRAILSTART+ pipsy2 = max(x2 * ProfitPerCent, y2) //y = % of max profitENDIFIF y2 THENy2 = y2 * pipsize //convert Pips to PriceIF (TradePrice + y2) > close THEN //IF Tradeprice + Profit > CLOSE ...EXITSHORT AT MARKET //... exit immediatelyELSEEXITSHORT AT Tradeprice - y2 STOP //Place pending STOP order when y2>0ENDIFENDIFENDIFgraph fastMA coloured(0,200,0)graph slowma coloured(200,0,0)graph longma coloured(0,0,200)graph closeThe performance is not good (made with tick mode and spread=1.5), and as you can see in the attached picture, daily MA are not calculated until there is enough bars in the default timeframe (5-minute TF). This is something we should be aware of when backtesting… a test to verify if the SMA are superior to 0 could be enough..
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on