Hello. I share with the community an automatic strategy that works on the DAX for M5 timeframe.
I wanted to test a strategy that involves observing the angular orientation of a moving average. The higher the angle and slope of the moving average, the stronger and more directional the movement. It then took me back into my distant memories of mathematics courses, trigonometry and vector calculus to try to develop this code.
The strategy consists first of all in calculating the angular orientation of a 10-period moving average (PeriodA) over a period of 15 bars (nbChandelierA). Then I calculate the slope of this moving average. This amounts to calculating a “vector” hence the name of the algorithm.
I then added a trailing stop and optimized the entry points with particular playing on the variable “lag”.
I launched the code in real mode and in demo mode. There are some differences in the positions, but overall it works pretty well.
Note that the attached backtest images correspond to a backtest on 200,000 bars (Premium version of PRT) with a spread of 1.5 points.
The code looks good on other timeframes (including H4) by changing the variables.
Looking forward to having your feedback, feedback and suggestions for improvements.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
// ROBOT VECTORIAL DAX // M5 // SPREAD 1.5 // by BALMORA 74 - FEBRUARY 2019 DEFPARAM CumulateOrders = false DEFPARAM Preloadbars = 50000 //VARIABLES CtimeA = time >= 080000 and time <= 220000 CtimeB = time >= 080000 and time <= 220000 ONCE BarLong = 950 //EXIT ZOMBIE TRADE LONG ONCE BarShort = 650 //EXIT ZOMBIE TRADE SHORT // TAILLE DES POSITIONS ONCE PositionSizeLong = 1 ONCE PositionSizeShort = 2 //STRATEGIE //VECTEUR = CALCUL DE L'ANGLE ONCE PeriodeA = 10 ONCE nbChandelierA= 15 MMA = Exponentialaverage[PeriodeA](close) ADJASUROPPO = (MMA-MMA[nbchandelierA]*pipsize) / nbChandelierA ANGLE = (ATAN(ADJASUROPPO)) //FONCTION ARC TANGENTE CondBuy1 = ANGLE >= 45 CondSell1 = ANGLE <= - 37 //VECTEUR = CALCUL DE LA PENTE ET SA MOYENNE MOBILE ONCE PeriodeB = 20 ONCE nbChandelierB= 35 lag = 5 MMB = Exponentialaverage[PeriodeB](close) pente = (MMB-MMB[nbchandelierB]*pipsize) / nbchandelierB trigger = Exponentialaverage[PeriodeB+lag](pente) CondBuy2 = (pente > trigger) AND (pente < 0) CondSell2 = (pente CROSSES UNDER trigger) AND (pente > -1) //ENTREES EN POSITION CONDBUY = CondBuy1 and CondBuy2 and CTimeA CONDSELL = CondSell1 and CondSell2 and CtimeB //POSITION LONGUE IF CONDBUY THEN buy PositionSizeLong contract at market SET TARGET %PROFIT 4.25 ENDIF //POSITION COURTE IF CONDSELL THEN Sellshort PositionSizeShort contract at market SET TARGET %PROFIT 1.25 ENDIF //VARIABLES STOP SUIVEUR ONCE trailingStopType = 1 // Trailing Stop - 0 OFF, 1 ON ONCE trailingstoplong = 7.5 // Trailing Stop Atr Relative Distance ONCE trailingstopshort = 4 // Trailing Stop Atr Relative Distance ONCE atrtrailingperiod = 25 // Atr parameter Value ONCE minstop = 0 // Minimum Trailing Stop Distance // TRAILINGSTOP //---------------------------------------------- atrtrail = AverageTrueRange[atrtrailingperiod]((close/10)*pipsize)/1000 trailingstartl = round(atrtrail*trailingstoplong) trailingstartS = round(atrtrail*trailingstopshort) if trailingStopType = 1 THEN TGL =trailingstartl TGS=trailingstarts if not onmarket then MAXPRICE = 0 MINPRICE = close PREZZOUSCITA = 0 ENDIF if longonmarket then MAXPRICE = MAX(MAXPRICE,close) if MAXPRICE-tradeprice(1)>=TGL*pointsize then if MAXPRICE-tradeprice(1)>=MINSTOP then PREZZOUSCITA = MAXPRICE-TGL*pointsize ELSE PREZZOUSCITA = MAXPRICE - MINSTOP*pointsize ENDIF ENDIF ENDIF if shortonmarket then MINPRICE = MIN(MINPRICE,close) if tradeprice(1)-MINPRICE>=TGS*pointsize then if tradeprice(1)-MINPRICE>=MINSTOP then PREZZOUSCITA = MINPRICE+TGS*pointsize ELSE PREZZOUSCITA = MINPRICE + MINSTOP*pointsize ENDIF ENDIF ENDIF if onmarket and PREZZOUSCITA>0 then EXITSHORT AT PREZZOUSCITA STOP SELL AT PREZZOUSCITA STOP ENDIF ENDIF //EXIT ZOMBIE TRADE IF POSITIONPERF<0 THEN IF shortOnMarket AND BARINDEX-TRADEINDEX(1)>= barshort THEN EXITSHORT AT MARKET ENDIF ENDIF IF POSITIONPERF<0 THEN IF LongOnMarket AND BARINDEX-TRADEINDEX(1)>= barlong THEN SELL AT MARKET ENDIF ENDIF |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Thanks for this contribution to our library! Did you try Out Of Sample (OOS) tests after optimization? or even in backtest by optimizing only a single part of the history?
Not yet but i’ll try to do it. Is it possible to open a file discussion in the French or English forum in order to share ideas and trying to improve this strategy ?
English topic should drain more people!
Link to the forum : https://www.prorealcode.com/topic/vectorial-dax-m5/
Thanks for sharing that Balmora. Nice work.
Hallo Balmora74,
you wrote: “The code looks good on other timeframes (including H4) by changing the variables.”
How do you change the variables on which timeframes?
Hello Superborstig. Fore more info : https://www.prorealcode.com/topic/vectorial-dax-m5/
Hi, nice piece of work, using atan.
My question: MMA is constituted by the 10 most recent bars (PeriodeA=10). Why not also assign nbChandelierA with the same value 10? That would make your algo more consistent. The same goes for the couple in ~B.
Regards, Jerke
Hi Jerke and thanks for your return. I choose the values because they gave me the best equity curve… But i will try to test the strategy with the same values for couples in A and B…
Great work I’ve changed the trade quantity to reflect whether price is above or below the 200 day moving average a “buy” of 2 if above this average and a sell of 1 and for a “sell” of 2 if below the average and 1 if above. Makes little difference on the most recent 100000 units but I think gives better logic in the light of current trend.
Hello Balmora, good morning.
Nice code, Thanks for sharing. I just read from your comments that you are using this strategy in live and demo.
I am just asking how to move this code to live.
As far as I know with ProRealTime and IB (interactive Broker) you can not use ProOrder Automatic trading.
You can only use this with IG CFDs…
I have some codes in demo and I would like to move forward to live. Any help I will apreciate.
Thanks a lot Regards Paco
@Pacolopez read this :
https://www.prorealcode.com/topic/main-differences-prorealtime-software-prorealtime-ib-and-prorealtime-ig/
@Pacolopez
Hi ! I run this code live on IG CFDs (not via IG Interactive Broker).
Hi
How does it go on live ?
JC
Thanks Balmora74.
100% clear now.
Not posible at all with IB
Only option by now with IG
Thanks Regards Paco
Hi BALMORA, looks like a good compliment algorithm. I tried to test it on the EUR USD but it doesn’t calculate any trade, how come?
Hello, how did you optimized all these variable? If I try to optimize only two variables it takes hours and often the software crashes.
Thanks in advance and compliment for this algorithm! Marco
Great work ! My only concern is about risk management. Your results are based on 10k. Max loss 500euro. Its mean 5% max loss by trade. Ratio Risk-Reward is approx. 1:1. My problem with that is consecutive lost that can ruine you in a losing strike. Have you try to play with ratio RR and max loss by trade ?
can we have a update on this one please?
Discussions with many other versions and improvements can be found here: https://www.prorealcode.com/topic/vectorial-dax-m5/
Balmora74, io vedo che funziona anche su timeframe ad 1 minuto con piccole ottimizzazioni, tu che ne pensi?
hola buenas, a este sistema automático, Cómo se le podría poner un stoploss de beneficio simple. sin alterar el sistema entero. Gracias.