Hi Gianluca. What is the unit of the variable “c” ? is it un degree ?
Hello everybody
I am a bit disappointed with my last tests because I have only good results with dax index in 5TF, nothing good on nasdaq or cac and results are not strong on doji.
Angle input does not seem to be adaptable ….easly
Tof
Quick question as I’m pretty new to this:
It seems like the only way the current position is closed is either via trailing stop (position is already in profit) or stop loss. However, I do get also smaller losses in the backtest which I can’t really pin to any part of the code. I’ve tried the modified version including Pauls suggestions.
Hi Zebra. There is a other possibility for a position to be closed automatically. This is when the code detects a reverse position at the current position. Then the current position is closed and a other position is opened in the opposite direction. This can explain what you see in the backtest.
Ah right, overlooked that as most of the strategies on the platform have a check for current open positions before they open a position to the opposite site. Thanks for the hint Balmora !
To avoid this you can add condition in buy and sell conditions. For example IF NOT ONMARKET / IF NOT SHORTONMARKET / IF NOT LONGONMARKET
but with my versus can you have a dynamic stop loss…
Hello,
How could the strategy code be modified to have increasing lots taking into account reinvested profits?
Thanks!
Hello, How could the strategy code be modified to have increasing lots taking into account reinvested profits? Thanks!
Type ‘Money management’ in the search box and plenty of coding ideas will be available or try some of the Lot Size code snippets that can be found here:
https://docs.google.com/spreadsheets/d/1rgboqj7sVwsP9ZRhOduOefye48QMWC07jWVXCl-KJPU/edit#gid=0
Just for info … Cell G1 of the above sheet has the link given as
Snippet Link Library … if you ever need it Vonasi or anybody.
Just for info … Cell G1 of the above sheet has the link given as
Snippet Link Library … if you ever need it Vonasi or anybody.
Way beyond my intelligence level – I just typed ‘Snippet Library’ in the search box!
I just don’t know how to code it… Could someone could add this to the paul version? Thanks
@ Jebus89 – did you try to run another optimization?
I just don’t know how to code it… Could someone could add this to the paul version? Thanks
Here you go. It has three forms of position sizing and also a risk based position size multiplier that means size is increased more rapidly as profits increase. You can select all this by changing settings in lines 10 to 14.
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 = 0 = risk management off and 1 = risk management on. I do not recommend using this it can blow up your account very easily!
Capital = Starting capital
MinBetSize = The minimum bet size allowed for the instrument.
RiskLevel = A factor that changes how fast position size increases as profit increases. Only relevant if Risk Management is turned on.
//ROBOT VECTORIAL DAX
// M5
// SPREAD 1.5
// by BALMORA 74 - FEBRUARY 2019
//Money Management added by Vonasi
DEFPARAM CumulateOrders = false
DEFPARAM Preloadbars = 50000
MoneyManagement = 2
RiskManagement = 0
Capital = 10000
MinBetSize = 1
RiskLevel = 20
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*100)
PositionSize = PositionSize/100
//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
PositionSizeLong = 1 * positionsize
PositionSizeShort = 2 * 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 >= 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
I hadn’t looked at this strategy much until I added my money management code to it in the last post. Whilst doing this it became obvious that there is one massive curve fit that makes performance look better than it is – and that is doubling the position size for short trades compared to long trades. The last 100K bars show that on the DAX there has been a definite down trend so this doubling of position size fits these bars just right but imagine what could happen if the next 100K bars have a definite up trend. You would be losing twice as much as you are winning. I would personally remove this position size doubling from the code.
[attachment file=94191]
As a follow up to my last post – notice how it has failed to make any profit at all in what has been a strong recent up trend.
[attachment file=”94194″]