Hi everyone,
Here is a new strategy on Hang Seng 1 min TF. It measures the angle of the slope and looking for a V-slope. As unit of price and bar is not the same, thus replaced the bar with ATR (with higher period) to have in relative price to price comparison.
Looking forward for your suggestion and ideas of improvement.
DEFPARAM CumulateOrders = false
DEFPARAM PRELOADBARS = 2000
//Money Management
MM = 0 // = 0 for optimization
if MM = 0 then
positionsize = 1
ENDIF
if MM = 1 then
once maxSize = 2
once minSize = 1
once startingsize = 1
once stepsize = 0.5
once resetafterlost = 0
once doublestepdown = 0
once resetafterstrikewin = 2
once positionsize = startingsize
once wincount = 0
if strategyprofit <> strategyprofit[1] then
if positionperf(1)>0 then
if positionsize < maxSize then
positionsize = positionsize + stepsize
endif
wincount = wincount + 1
if wincount >= resetafterstrikewin then
positionsize = startingsize
wincount = 0
endif
else
if resetafterlost then
positionsize = startingsize
elsif doublestepdown then
positionsize = positionsize - stepsize * 2
else
positionsize = positionsize - stepsize
endif
wincount = 0
endif
endif
if positionsize < minSize then
positionsize = minSize
endif
ENDIF
timedaytrade = (time > 093100 + waitmin) AND (time < 120000) OR (time > 130000 + waitmin AND time < 155500)
timeok = timedaytrade
//====== Enter market - start =====
samebarsignal = 0
M1atrAB = AverageTrueRange[periodA + periodB](close)
//Look for V shape
adjacentA = (close - close[periodA]) / M1atrAB
angelA = atan(adjacentA)
adjacentB = (close[periodA] - close[periodA + periodB]) / M1atrAB[periodA]
angelB = atan(adjacentB)
C1 = angelB < longB AND angelA > longA
// LONG side
IF timeok AND Not OnMarket AND C1 AND samebarsignal = 0 THEN
BUY positionsize CONTRACT AT MARKET
SET STOP pLOSS SL
TP = RR * SL
SET TARGET pPROFIT TP
samebarsignal = 1
ENDIF
//====== Enter market - end =====
//====== Exit market - start =====
IF NOT ONMARKET THEN
ENDIF
//====== Exit market - end =====
Hi,
Can you try to backtest this strategy with a breakeven and maybe a filter on M5
With 200k, i get 100%.
for example
DEFPARAM CumulateOrders = false
DEFPARAM PRELOADBARS = 2000
//Money Management
MM = 0 // = 0 for optimization
if MM = 0 then
positionsize = 1
ENDIF
if MM = 1 then
once maxSize = 2
once minSize = 1
once startingsize = 1
once stepsize = 0.5
once resetafterlost = 0
once doublestepdown = 0
once resetafterstrikewin = 2
once positionsize = startingsize
once wincount = 0
if strategyprofit <> strategyprofit[1] then
if positionperf(1)>0 then
if positionsize < maxSize then
positionsize = positionsize + stepsize
endif
wincount = wincount + 1
if wincount >= resetafterstrikewin then
positionsize = startingsize
wincount = 0
endif
else
if resetafterlost then
positionsize = startingsize
elsif doublestepdown then
positionsize = positionsize - stepsize * 2
else
positionsize = positionsize - stepsize
endif
wincount = 0
endif
endif
if positionsize < minSize then
positionsize = minSize
endif
ENDIF
timedaytrade = (time > 093100 + waitmin) AND (time < 120000) OR (time > 130000 + waitmin AND time < 155500)
timeok = timedaytrade
timeframe(5minutes,updateonclose)
st = close > supertrend[5,4]
timeframe(default)
//====== Enter market - start =====
samebarsignal = 0
M1atrAB = AverageTrueRange[periodA + periodB](close)
//Look for V shape
adjacentA = (close - close[periodA]) / M1atrAB
angelA = atan(adjacentA)
adjacentB = (close[periodA] - close[periodA + periodB]) / M1atrAB[periodA]
angelB = atan(adjacentB)
C1 = angelB < longB AND angelA > longA
// LONG side
IF timeok AND Not OnMarket AND C1 AND samebarsignal = 0 and st THEN
BUY positionsize CONTRACT AT MARKET
SET STOP pLOSS SL
TP = RR * SL
SET TARGET pPROFIT TP
samebarsignal = 1
ENDIF
//====== Enter market - end =====
//====== Exit market - start =====
IF NOT ONMARKET THEN
ENDIF
//====== Exit market - end =====
// breakeven stop atr
once breakevenstoptype = 1 // breakeven stop - 0 off, 1 on
once breakevenstoplong = 1 // breakeven stop atr relative distance
once breakevenstopshort = 1 // breakeven stop atr relative distance
once pointstokeep = 5 // positive or negative
once atrperiodbreakeven = 14 // atr parameter value
once minstopbreakeven = 36 // minimum breakeven stop distance
//----------------------------------------------
atrbreakeven = averagetruerange[atrperiodbreakeven]((close/10)*pipsize)/1000
//atrbreakeven=averagetruerange[atrperiodbreakeven]((close/1)*pipsize) // (forex)
bestopl = round(atrbreakeven*breakevenstoplong)
bestops = round(atrbreakeven*breakevenstopshort)
if breakevenstoptype = 1 then
//
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
maxpricebe = 0
minpricebe = close
newslbe = 0
endif
//
if longonmarket then
maxpricebe = max(maxpricebe,close)
if maxpricebe-tradeprice(1)>=bestopl*pointsize then
if maxpricebe-tradeprice(1)>=minstopbreakeven then
newslbe=tradeprice(1)+pointstokeep*pipsize
else
newslbe=tradeprice(1)- minstopbreakeven*pointsize
endif
endif
endif
//
if shortonmarket then
minpricebe = min(minpricebe,close)
if tradeprice(1)-minpricebe>=bestops*pointsize then
if tradeprice(1)-minpricebe>=minstopbreakeven then
newslbe = tradeprice(1)-pointstokeep*pipsize
else
newslbe = tradeprice(1) + minstopbreakeven*pointsize
endif
endif
endif
//
if longonmarket then
if newslbe>0 then
sell at newslbe stop
endif
if newslbe>0 then
if low < newslbe then
sell at market
endif
endif
endif
//
if shortonmarket then
if newslbe>0 then
exitshort at newslbe stop
endif
if newslbe>0 then
if high > newslbe then
exitshort at market
endif
endif
endif
endif
Thanks @MAKSIDE for the idea.
For the 100% result, I guess you mean win rate? Not sure why, but I don’t get the same result with the parameters I set in the .itf.
If re-optimize the parameters, I have some combination giving 100% win rate, but the trade number is way too low <5. Do you observe the same?
If possible, can you please share the .itf?
Thanks. It seems the trades are too little. I’m not expert, but personally, I felt the number of trade is too little to justify the consistency thus I will not have confident. But just me…
hello how did you define x and y to make the code work?
I don’t see an optimization report to help with the decision ..? Thank you Best regards.
Hi DowJones
Thanks for your work
Something I dn’t understand is the ATR instead of a number of bars ?
adjacentB = (close[periodA] - close[periodA + periodB]) / M1atrAB[periodA]
angelB = atan(adjacentB)
Because to calculate Arctangente you need the opposite side : (close[periodA] – close[periodA + periodB] Thant’s ok
But M1atrAB[periodA] is not the adajacent side ?
I understand your explannations but don’t think it will be the same
Cheers
And I don’t understand this part of your code
if resetafterlost then
positionsize = startingsize
elsif doublestepdown then
positionsize = positionsize - stepsize * 2
else
positionsize = positionsize - stepsize
endif
wincount = 0
endif
Because I think you decrement position size when position perf is negative but resetafterlost is always at 0 and doublestepdown too.
Does something mis as a count on loss trades ?
Thanks
I understand your explannations but don’t think it will be the same
Hi @zilliq, indeed. I understand your concern. Using ATR is just taking the reference where x bar in average moved by y point (range). Rather than taking directly the bar, because the bar unit is totally not relevant with point unit. For sure both analogy is still not the same like measuring with ruler with centimeter, but at least using bar vs point are less relevant, e.g. from 5 bars, it moves from 21000 to 21150, so taking arctan of 5 and 150 vs from 5 bars, ATR is 50, it moves from 21000 to 21150, so taking arctan of 50 and 150
but resetafterlost is always at 0 and doublestepdown too
From GRAPH, right? Because I never activate it (line 5) 🙂 I left it like a template and forget to remove it.
MM = 0 // = 0 for optimization
Thanks for you answer Dowjones. I understand for ATR, it’s a different point of view
For the second part, sorry for my bad explanations
I said that resetafterlost is always at 0 so the condition is always at ON (instead to be at 0 some times and if positionsperf(1)<0 to be at 1 for example) and same for doublestepdown. So how can the code understand wich choice to use ?
Hope to be clear
So how can the code understand wich choice to use ?
Ah, sorry for misunderstanding. These are actually configuration parameter, to be chosen accordingly which is preferred.
once maxSize = 2
once minSize = 1
once startingsize = 1
once stepsize = 0.5
once resetafterlost = 0
once doublestepdown = 0
once resetafterstrikewin = 2
Whether you prefer to reset the lot back to startingsize once hit a single loss trade, or you prefer to doublestepdown. It is choice need to be made.
So if you choose resetafterlost, then doublestepdown will not be applicable even if you set it to 1. By default, all are set to 0, so once there is a loss trade, the lot size will be reduced by sizestep
Understand, Thanks
I thought it depends of the configuration of the code
have a nice evening