ProRealCode - Trading & Coding with ProRealTime™
Here is my version, with a different angle (WF).
Improvments and suggestions are welcome!
// ROBOT VECTORIAL DAX V.3
// M5
// SPREAD 1.5
// by BALMORA 74 - FEBRUARY 2019 /// winnie version 10/04/12019
DEFPARAM CumulateOrders = false
DEFPARAM Preloadbars = 50000
//VARIABLES
CtimeA = time >= 080000 and time <= 180000
CtimeB = time >= 080000 and time <= 180000
ONCE BarLong = 950 //EXIT ZOMBIE TRADE LONG
ONCE BarShort = 650 //EXIT ZOMBIE TRADE SHORT
MoneyManagement = 2
//MoneyManagement = Set to 0 for level stakes. Set to 1 for increasing stake size as profits increase and decreasing stake size as profits decrease. Set to 2 for increasing stake size as profits increase with stake size never being decreased.
RiskManagement = 1
//RiskManagement = 0 = risk management off and 1 = risk management on. I do not recommend using this it can blow up your account very easily!
Capital = 10000
MinBetSize = 1
//MinBetSize = The minimum bet size allowed for the instrument.
RiskLevel = 10
//RiskLevel =A factor that changes how fast position size increases as profit increases. Only relevant if Risk Management is turned on.
Equity = Capital + StrategyProfit
IF MoneyManagement = 1 THEN
PositionSize = Max(MinBetSize, Equity * (MinBetSize/Capital))
ENDIF
IF MoneyManagement = 2 THEN
PositionSize = Max(LastSize, Equity * (MinBetSize/Capital))
LastSize = PositionSize
ENDIF
IF MoneyManagement <> 1 and MoneyManagement <> 2 THEN
PositionSize = MinBetSize
ENDIF
IF RiskManagement THEN
IF Equity > Capital THEN
RiskMultiple = ((Equity/Capital) / RiskLevel)
PositionSize = PositionSize * (1 + RiskMultiple)
ENDIF
ENDIF
PositionSize = Round(PositionSize)
// TAILLE DES POSITIONS
PositionSizeLong = 1 * positionsize
PositionSizeShort = 1 * positionsize
//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 >= 20
CondSell1 = ANGLE <= - 24
//VECTEUR = CALCUL DE LA PENTE ET SA MOYENNE MOBILE
ONCE PeriodeB = 20
ONCE nbChandelierB= 35
lag = 1.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 STOP %LOSS 2
ENDIF
//POSITION COURTE
IF CONDSELL THEN
Sellshort PositionSizeShort contract at market
SET STOP %LOSS 2
ENDIF
//VARIABLES STOP SUIVEUR
ONCE trailingStopType = 1 // Trailing Stop - 0 OFF, 1 ON
ONCE trailingstoplong = 4 // Trailing Stop Atr Relative Distance
ONCE trailingstopshort = 4 // Trailing Stop Atr Relative Distance
ONCE atrtrailingperiod = 14 // 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
Hi Winnie. Thanks for sharing your researchs
From my side I worked on an improved version based on Paul’s suggestions
I kept the values of original angles but I did a backtest using Walk Forward to optimize the variable “lag” and I’m OK like you for lag = 1.5.
Otherwise I added a 3rd condition for LONG and SHORT based on the orientation of a medium-term moving average :
CondBuy3 = average[100](close) > average[100](close)[1]
CondSell3 = average[20](close) < average[20](close)[1]
It gives less number of positions / less drawdown and a better profit factor.
Below are the results and the .ITF file.
It is quite possible that the algorithm is over fitted and over optimized. Reason why I put the code in account demo to observe its behavior over 6 months to 1 year…
I will it share it after….
// ROBOT VECTORIAL DAX v2
// M5
// SPREAD = 1
// by BALMORA 74 - APRIL 2019
DEFPARAM CumulateOrders = false
DEFPARAM Preloadbars = 50000
//TRADING TIME
CtimeA = time >= 080000 and time <= 180000
CtimeB = time >= 080000 and time <= 180000
//POSITION SIZE
PositionSize = 1
//STRATEGY
ONCE PeriodeA = 10
ONCE nbChandelierA= 15
ONCE PeriodeB = 20
ONCE nbChandelierB= 35
ONCE lag = 1.5
MMA = Exponentialaverage[PeriodeA](close)
ADJASUROPPO = (MMA-MMA[nbchandelierA]*pipsize) / nbChandelierA
ANGLE = (ATAN(ADJASUROPPO))
CondBuy1 = ANGLE >= 35
CondSell1 = ANGLE <= - 40
MMB = Exponentialaverage[PeriodeB](close)
pente = (MMB-MMB[nbchandelierB]*pipsize) / nbchandelierB
trigger = Exponentialaverage[PeriodeB+lag](pente)
//BUY CONDITIONS
CondBuy1 = ANGLE >= 35
CondBuy2 = (pente > trigger) AND (pente < 0)
CondBuy3 = average[100](close) > average[100](close)[1]
CONDBUY = CondBuy1 and CondBuy2 and CondBuy3 and CTimeA
//SHORT CONDITIONS
CondSell1 = ANGLE <= - 40
CondSell2 = (pente CROSSES UNDER trigger) AND (pente > -1)
CondSell3 = average[20](close) < average[20](close)[1]
CONDSELL = CondSell1 and CondSell2 and CondSell3 and CtimeB
//POSITION LONGUE
IF CONDBUY THEN
buy PositionSize contract at market
SET STOP %LOSS 2
ENDIF
//POSITION COURTE
IF CONDSELL THEN
Sellshort PositionSize contract at market
SET STOP %LOSS 2
ENDIF
//TRAILING STOP
ONCE trailingStopType = 1 // Trailing Stop - 0 OFF, 1 ON
ONCE trailingstoplong = 4 // Trailing Stop Atr Relative Distance
ONCE trailingstopshort = 4 // Trailing Stop Atr Relative Distance
ONCE atrtrailingperiod = 14 // 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
Is there redundant code in this strategy or can anybody offer a reason for the following please?
When I optimise the angles, it seems that almost any value gives the same figure for Gain … see attached.
Attached is related to the code version immediately above this post.
Hi Balmara74,
thanks for your improvment. I run it too. Another idea to improve tue strategy would be to include and test this part of code, very interesting…
https://www.prorealcode.com/blog/learning/how-to-improve-a-strategy-with-simulated-trades-1/
I tried to do it yesterday but i’m not a professionnal coder ;), so some difficulties and errors to do it. Could you try?
Did you test the strategy on 200K?
@Grahal
Maybe because you use a negative angle value for variable A28.
It could be interesting to use a value between 0 and +90 (knowing that the more one deviates from 45 and less positions we have).
EDIT POST – ERROR FOUND !!
I found a error on the code above !! Yes it’s redudant because LINES 27 and 28 are the same than LINES 34 and 40
So this is the good version of the code below (i have delete lines 27 and 28) :
// ROBOT VECTORIAL DAX v2
// M5
// SPREAD = 1
// by BALMORA 74 - APRIL 2019
DEFPARAM CumulateOrders = false
DEFPARAM Preloadbars = 50000
//TRADING TIME
CtimeA = time >= 080000 and time <= 180000
CtimeB = time >= 080000 and time <= 180000
//POSITION SIZE
PositionSize = 1
//STRATEGY
ONCE PeriodeA = 10
ONCE nbChandelierA= 15
ONCE PeriodeB = 20
ONCE nbChandelierB= 35
ONCE lag = 1.5
MMA = Exponentialaverage[PeriodeA](close)
ADJASUROPPO = (MMA-MMA[nbchandelierA]*pipsize) / nbChandelierA
ANGLE = (ATAN(ADJASUROPPO))
MMB = Exponentialaverage[PeriodeB](close)
pente = (MMB-MMB[nbchandelierB]*pipsize) / nbchandelierB
trigger = Exponentialaverage[PeriodeB+lag](pente)
//BUY CONDITIONS
CondBuy1 = ANGLE >= 35
CondBuy2 = (pente > trigger) AND (pente < 0)
CondBuy3 = average[100](close) > average[100](close)[1]
CONDBUY = CondBuy1 and CondBuy2 and CondBuy3 and CTimeA
//SHORT CONDITIONS
CondSell1 = ANGLE <= - 40
CondSell2 = (pente CROSSES UNDER trigger) AND (pente > -1)
CondSell3 = average[20](close) < average[20](close)[1]
CONDSELL = CondSell1 and CondSell2 and CondSell3 and CtimeB
//POSITION LONGUE
IF CONDBUY THEN
buy PositionSize contract at market
SET STOP %LOSS 2
ENDIF
//POSITION COURTE
IF CONDSELL THEN
Sellshort PositionSize contract at market
SET STOP %LOSS 2
ENDIF
//TRAILING STOP
ONCE trailingStopType = 1 // Trailing Stop - 0 OFF, 1 ON
ONCE trailingstoplong = 4 // Trailing Stop Atr Relative Distance
ONCE trailingstopshort = 4 // Trailing Stop Atr Relative Distance
ONCE atrtrailingperiod = 14 // 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
I am going to run this code live.
A little more fun then 🙂
In order for the losses not to be too large you can sell ex.. 0.5 contracts directly after a position is taken.
It will be lower DD as well.
How do you code this?
I currently have 5 algo live on dax.
Unfortunately, they have gone bad at the same time and it is expensive.
I am going to run them on demo now instead.I currently have 5 algo live on dax. Unfortunately, they have gone bad at the same time and it is expensive. I am going to run them on demo now instead.I would suggest always running any strategies in a lengthy live forward test in demo to confirm that they are not curve fitted. Yes it is a bit boring and not as exciting as going live but your patience will save you from losing an awful lot of money in the long run. I have strategies that have had on test for a year or more now. They are very profitable but the draw down was bigger than in the in sample test and would have sucked my real account dry if I had just gone live with them. Patience pays!
I tested your code on nasdaq.
changed sl and tp and time.
// ROBOT VECTORIAL DAX v2
// M5
// SPREAD = 1
// by BALMORA 74 - APRIL 2019
DEFPARAM CumulateOrders = false
DEFPARAM Preloadbars = 50000
//TRADING TIME
CtimeA = time >= 150000 and time <= 220000
CtimeB = time >= 150000 and time <= 220000
//POSITION SIZE
PositionSize = 1
//STRATEGY
ONCE PeriodeA = 10
ONCE nbChandelierA= 15
ONCE PeriodeB = 20
ONCE nbChandelierB= 35
ONCE lag = 1.5
MMA = Exponentialaverage[PeriodeA](close)
ADJASUROPPO = (MMA-MMA[nbchandelierA]*pipsize) / nbChandelierA
ANGLE = (ATAN(ADJASUROPPO))
MMB = Exponentialaverage[PeriodeB](close)
pente = (MMB-MMB[nbchandelierB]*pipsize) / nbchandelierB
trigger = Exponentialaverage[PeriodeB+lag](pente)
//BUY CONDITIONS
CondBuy1 = ANGLE >= 35
CondBuy2 = (pente > trigger) AND (pente < 0)
CondBuy3 = average[100](close) > average[100](close)[1]
CONDBUY = CondBuy1 and CondBuy2 and CondBuy3 and CTimeA
//SHORT CONDITIONS
CondSell1 = ANGLE <= - 40
CondSell2 = (pente CROSSES UNDER trigger) AND (pente > -1)
CondSell3 = average[20](close) < average[20](close)[1]
CONDSELL = CondSell1 and CondSell2 and CondSell3 and CtimeB
//POSITION LONGUE
IF CONDBUY THEN
buy PositionSize contract at market
SET STOP %LOSS 2
ENDIF
//POSITION COURTE
IF CONDSELL THEN
Sellshort PositionSize contract at market
SET STOP %LOSS 2
ENDIF
//TRAILING STOP
ONCE trailingStopType = 1 // Trailing Stop - 0 OFF, 1 ON
ONCE trailingstoplong = 8 // Trailing Stop Atr Relative Distance
ONCE trailingstopshort = 5 // Trailing Stop Atr Relative Distance
ONCE atrtrailingperiod = 30 // 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
I tested your code on nasdaq.Not my code!
Not my code!Not even your name! 🙂 Couldn’t resist sorry … as you said Vonasi trading can be lonely and I do enjoy a laugh even if it me making myself laugh!
Discussing the strategy VECTORIAL DAX (M5)
This topic contains 1,263 replies,
has 125 voices, and was last updated by VinzentVega
1 year ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 02/24/2019 |
| Status: | Active |
| Attachments: | 470 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.