Discussing the strategy VECTORIAL DAX (M5)
03/20/2019 at 9:33 PM #94203
Hi Vonasi ! I recently worked on a new version of the code based on the various suggestions of this thread (Paul and Jebus89 in particular). I also did a Walk Forward on the variable “lag”. I also took into account your recommendations on the size of the positions and I added your code on money management. Here is the code and below the results. I would be happy to have your feedback and opinion. Thank you.Vectorial - DAX WFE1.1123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139// ROBOT VECTORIAL DAX// M5// SPREAD 1.5// by BALMORA 74 - FEBRUARY 2019DEFPARAM CumulateOrders = falseDEFPARAM Preloadbars = 50000//VARIABLESCtimeA = time >= 080000 and time <= 180000CtimeB = time >= 080000 and time <= 180000MoneyManagement = 2RiskManagement = 0Capital = 10000MinBetSize = 1RiskLevel = 20Equity = Capital + StrategyProfitIF MoneyManagement = 1 THENPositionSize = Max(MinBetSize, Equity * (MinBetSize/Capital))ENDIFIF MoneyManagement = 2 THENPositionSize = Max(LastSize, Equity * (MinBetSize/Capital))LastSize = PositionSizeENDIFIF MoneyManagement <> 1 and MoneyManagement <> 2 THENPositionSize = MinBetSizeENDIFIF RiskManagement THENIF Equity > Capital THENRiskMultiple = ((Equity/Capital) / RiskLevel)PositionSize = PositionSize * (1 + RiskMultiple)ENDIFENDIFPositionSize = Round(PositionSize)// TAILLE DES POSITIONSPositionSizeLong = 1 * positionsizePositionSizeShort = 1 * positionsize//STRATEGIE//VECTEUR = CALCUL DE L'ANGLEONCE PeriodeA = 10ONCE nbChandelierA= 15MMA = Exponentialaverage[PeriodeA](close)ADJASUROPPO = (MMA-MMA[nbchandelierA]*pipsize) / nbChandelierAANGLE = (ATAN(ADJASUROPPO)) //FONCTION ARC TANGENTECondBuy1 = ANGLE >= 35CondSell1 = ANGLE <= - 40//VECTEUR = CALCUL DE LA PENTE ET SA MOYENNE MOBILEONCE PeriodeB = 20ONCE nbChandelierB= 35lag = 1.5MMB = Exponentialaverage[PeriodeB](close)pente = (MMB-MMB[nbchandelierB]*pipsize) / nbchandelierBtrigger = Exponentialaverage[PeriodeB+lag](pente)CondBuy2 = (pente > trigger) AND (pente < 0)CondSell2 = (pente CROSSES UNDER trigger) AND (pente > -1)//ENTREES EN POSITIONCONDBUY = CondBuy1 and CondBuy2 and CTimeACONDSELL = CondSell1 and CondSell2 and CtimeB//POSITION LONGUEIF CONDBUY THENbuy PositionSizeLong contract at marketSET STOP %LOSS 2ENDIF//POSITION COURTEIF CONDSELL THENSellshort PositionSizeShort contract at marketSET STOP %LOSS 2ENDIF//VARIABLES STOP SUIVEURONCE trailingStopType = 1 // Trailing Stop - 0 OFF, 1 ONONCE trailingstoplong = 4 // Trailing Stop Atr Relative DistanceONCE trailingstopshort = 4 // Trailing Stop Atr Relative DistanceONCE atrtrailingperiod = 14 // Atr parameter ValueONCE minstop = 0 // Minimum Trailing Stop Distance// TRAILINGSTOP//----------------------------------------------atrtrail = AverageTrueRange[atrtrailingperiod]((close/10)*pipsize)/1000trailingstartl = round(atrtrail*trailingstoplong)trailingstartS = round(atrtrail*trailingstopshort)if trailingStopType = 1 THENTGL =trailingstartlTGS=trailingstartsif not onmarket thenMAXPRICE = 0MINPRICE = closePREZZOUSCITA = 0ENDIFif longonmarket thenMAXPRICE = MAX(MAXPRICE,close)if MAXPRICE-tradeprice(1)>=TGL*pointsize thenif MAXPRICE-tradeprice(1)>=MINSTOP thenPREZZOUSCITA = MAXPRICE-TGL*pointsizeELSEPREZZOUSCITA = MAXPRICE - MINSTOP*pointsizeENDIFENDIFENDIFif shortonmarket thenMINPRICE = MIN(MINPRICE,close)if tradeprice(1)-MINPRICE>=TGS*pointsize thenif tradeprice(1)-MINPRICE>=MINSTOP thenPREZZOUSCITA = MINPRICE+TGS*pointsizeELSEPREZZOUSCITA = MINPRICE + MINSTOP*pointsizeENDIFENDIFENDIFif onmarket and PREZZOUSCITA>0 thenEXITSHORT AT PREZZOUSCITA STOPSELL AT PREZZOUSCITA STOPENDIFENDIF03/20/2019 at 9:57 PM #94209
My at glance feelings are that there are quite a number of variables that could all be curve fitted or a combination of variables be curve fitted which is going to be quite a bit of analysis to see how much affect each variable or combination of variables has. Even simple variables like the stop loss distances can be very curve fitted and will need to be included or eliminated from the analysis.
One thing I do notice is that you have MINSTOP set to zero which will always massively improve a strategy performance. In the real world the brokers set a minimum stop distance and even change this based on volatility so a setting of zero is the perfect world and the perfect world is not something we can trade in!03/20/2019 at 10:13 PM #94211
Yes i understand. But a interesting thing is that if you turn off the trailing stop (ONCE trailingStopType = 0) the equity curve is quite good and the strategy profit is the same (we just have a highest draw down).03/20/2019 at 10:18 PM #94213
I’ve given up trying to find a trailing stop that actually improves a strategy. It might just be my trading style but also there are usually too many variables in a trailing stop code that make me fear curve fitting.
Please post the non-trailing code equity curves if you can.
Also I would recommend only ever developing and forward testing with level stakes as money management just adds one extra level of confusion to strategy development. Once you are totally happy and confident in a strategy then add it and put it live if it still backtests well with the money management active.03/20/2019 at 10:23 PM #9421403/20/2019 at 10:30 PM #9421803/21/2019 at 8:21 AM #94236
That still looks like a very nice equity curve, especially considering the 49% win rate and proves that the trailing stop adds very little to the basic concept. Now you just need to check how various combinations of variables (including the % stop levels) change results to find out if you are sitting on a curve fitted cliff edge. Unfortunately I have to drive up to Athens and back again today so I won’t be able to help much with this.03/21/2019 at 9:13 AM #9424403/21/2019 at 4:05 PM #94325
I’m back from Athens now! Forward testing for a long period is the best test possible – and so much easier than testing and analysing all variable combinations in backtests!
1 user thanked author for this post.03/21/2019 at 4:56 PM #9433403/21/2019 at 5:40 PM #9434303/25/2019 at 10:41 AM #94605
Good morning everyone,
Thanks Balmora74 for this strategy, I am trying to run it on live demo since last thursday 21, but it took one trade that day and since then, last friday and today system stops because order requests fail… I am a newbie so I can´t understand why this is happening, if someone can help me to understand and try to solve it. Attach you can find the message I get and all the failed attempts from this morning. Thanks a lot in advance!03/25/2019 at 10:47 AM #94612
Hello capgros ! I have the same problem since friday on my account for different strategy based on CFD Dax 30 (1 euros). Strategy have shutdown and i have to re-start them manually. I think it’s perhaps a problem who can be linked to ongoing account migrations from IG Markets to IG Europe… ?03/25/2019 at 10:57 AM #94618
Aaaaah, maybe you are right, because it is the same for me, not only your strategy stopped but some of them, and some not. Ok I will keep restarting all of them manually and will see what´s going on next days. Will keep you updated. Cheers
1 user thanked author for this post.03/25/2019 at 11:18 AM #94636
See here for a discussion regarding stopped strategies and rejected orders.