Hi palettofix, thanks for that – your suggestion makes perfect sense. In fact I recently tried making that same change, but it gave me an unexpected result in tests so I left it with the full calculation each time – even though it looks like it should be unnecessary.
nonetheless
Good morning Nonetheless, Thank you very much for this valuable contribution. I’m wondering is line 139 shouldn’t read “>=” rather than “<=”
Thanks
yes, you’re right, that looks like a typo – sorry!
This is the version of that snippet I now use – sets a max number of bars whether the position is winning or losing.
//EXIT ZOMBIE TRADE
EZT = 1
if EZT then
IF (longonmarket and barindex-tradeindex(1)>= b1 and positionperf>0) or (longonmarket and barindex-tradeindex(1)>= b2 and positionperf<0) then
sell at market
endif
IF (shortonmarket and barindex-tradeindex(1)>= b3 and positionperf>0) or (shortonmarket and barindex-tradeindex(1)>= b4 and positionperf<0) then
exitshort at market
endif
endif
I’ve no doubt it was a typo. Thanks for the update. Cheers!
Actually that was already corrected in the later versions – v5 for example.
but looking at that template, the main thing I would change is the Money Management. This is the one I’m now using, although there are many others in the Snippet library.
//MONEY MANAGEMENT DAX II
MM = 0 // = 0 for optimization
if MM = 0 then
positionsize = 0.5
ENDIF
if MM then
MinSize = 0.5 // IG minimum position size allowed
MaxSize = 1050 // IG tier 2 margin limit
ProfitAccrued = 0 // when restarting strategy, enter profit or loss to date in instrument currency
DD = dd //MinSize drawdown in instrument currency
Multiplier = 3 //drawdown multiplier
Capital = DD * Multiplier
Equity = Capital + ProfitAccrued + StrategyProfit
PositionSize = Max(MinSize, Equity * (MinSize/Capital))
if positionsize > MaxSize then
positionsize = MaxSize
endif
PositionSize = Round(PositionSize*100)
PositionSize = PositionSize/100
ENDIF
Please keep sharing your treasure. I learnt a lot from you. THANK YOU!
Hi nonetheless,
I’m running tests on this simple strategy to better get grasp on how your BE/TrailingStop work. The code is below. It’s tested on DJ on 1 min chart (10k). The issue I’ve is after multiple runs of optimization, there are a few trades where the actual performance is way below the MFE, a few other reach a decent positive MFE and then end up negative.
I wonder if you can give me some advice on how to reduce the difference between MFE and actual performance and how to avoid finishing red after making 30pts positive. Do you use in your live systems a sort of staged parameters for each level of profit for example (eg. if positionperf >30 and <100 then tsl = x1 and tss=y1 // if positionperf >100 and <200 then tsl = x2 and tss=y2, etc.)?
Thanks
//-------------------------------------------------------------------------
// Code principal : MonSystème(136)
//-------------------------------------------------------------------------
DEFPARAM CUMULATEORDERS = FALSE
DEFPARAM PRELOADBARS = 2000
ONCE SL = 0.6
ONCE TPL = 0.6
ONCE TPS = 1.4
ONCE acceleratorlong = 0.3
ONCE acceleratorshort = 0.24
ONCE besensitivity = 1.0
ONCE besg = 0.01
ONCE besl = 0.01
ONCE ts2sensitivity = 3.0
ONCE tsl = 0.13
ONCE tss = 0.06
TIMEFRAME(60 minutes)
TrendUpH1 = close>open and close>close[1]
TrendDnH1 = close<open and close<close[1]
TIMEFRAME(5 minutes, UPDATEONCLOSE)
ca=0
cv=0
TrendUpM15 = close>open and close>close[1]
TrendDnM15 = close<open and close<close[1]
p = 12
q = 26
r = 9
z1=DEMA[p](close)
z2 =dema[q](close)
e= z1 - z2
z3=DEMA[r](e)
f=z3
g=e-f
ca1 = e < 0 and g>0
cv1 = e > 0 and g<0
ca = TrendUpM15 and TrendUpH1 and ca1
cv = TrendDnM15 and TrendDnH1 and cv1
TIMEFRAME(DEFAULT)
nLots = 1
IF NOT LongOnMarket AND ca THEN
BUY nLots CONTRACTS AT MARKET
ENDIF
IF NOT ShortOnMarket AND cv THEN
SELLSHORT nLots CONTRACTS AT MARKET
ENDIF
If LongOnMarket AND (cv) THEN
SELL AT MARKET
SELLSHORT nLots CONTRACTS AT MARKET
ENDIF
IF ShortOnMarket AND (ca) THEN
EXITSHORT AT MARKET
BUY nLots CONTRACTS AT MARKET
ENDIF
///////////////////////////
//////Breakeven 2////////
///////////////////////////
if POSITIONPERF>=(100)*pipsize then
enableBreakEven =1
// break even stop incl. cumulative positions
if enableBreakEven then
//====================
//once besg = be //% break even stop gain
//once besl = bes //% break even stop level (+ or -)
//besensitivity = 2 // 1 = close 2 = High/Low 3 = Low/High 4 = typicalprice (do not use once)
//====================
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
benewsl=0
mypositionpricebe = 0
endif
positioncountbe = abs(countofposition)
if benewsl > 0 then
if positioncountbe > positioncountbe[1] then
if longonmarket then
benewsl = max(benewsl,positionprice * benewsl / mypositionpricebe)
else
benewsl = min(benewsl,positionprice * benewsl / mypositionpricebe)
endif
endif
endif
if besensitivity=1 then
besensitivitylong=close
besensitivityshort=close
elsif besensitivity=2 then
besensitivitylong=high
besensitivityshort=low
elsif besensitivity=3 then
besensitivitylong=low
besensitivityshort=high
endif
if longonmarket then
if besensitivitylong-positionprice>=((positionprice/100)*besg)*pointsize then
benewsl=positionprice+((positionprice/100)*besl)*pointsize
endif
endif
if shortonmarket then
if positionprice-besensitivityshort>=((positionprice/100)*besg)*pointsize then
benewsl=positionprice-((positionprice/100)*besl)*pointsize
endif
endif
endif
mypositionpricebe = positionprice
if barindex-tradeindex>1 then
if longonmarket then
if benewsl>0 then
sell at benewsl stop
endif
if benewsl>0 then
if low crosses under benewsl then
sell at market
endif
endif
endif
if shortonmarket then
if benewsl>0 then
exitshort at benewsl stop
endif
if benewsl>0 then
if high crosses over benewsl then
exitshort at market
endif
endif
endif
endif
endif
///////////////////////////
//////Trailing Stop////////
///////////////////////////
trailingstopPC = 1
//endif
// Percentage trailing stop function incl. cumulative positions
if trailingstopPC then
trailingpercentlong = tsl // %
trailingpercentshort = tss // %
//once acceleratorlong = tsl/10 //a1 // always > 0 (typically TSL/10)
//once acceleratorshort= tss/10 //a2 // always > 0 (typically TSS/10)
//ts2sensitivity = 2 // 1 = close 2 = High/Low 3 = Low/High 4 = typicalprice (do not use once)
//====================
once steppercentlong = (trailingpercentlong/10)*acceleratorlong
once steppercentshort = (trailingpercentshort/10)*acceleratorshort
if onmarket then
trailingstartlong = positionprice*(trailingpercentlong/100)
trailingstartshort = positionprice*(trailingpercentshort/100)
trailingsteplong = positionprice*(steppercentlong/100)
trailingstepshort = positionprice*(steppercentshort/100)
endif
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
newsl = 0
mypositionprice = 0
endif
positioncount = abs(countofposition)
if newsl > 0 then
if positioncount > positioncount[1] then
if longonmarket then
newsl = max(newsl,positionprice * newsl / mypositionprice)
else
newsl = min(newsl,positionprice * newsl / mypositionprice)
endif
endif
endif
if ts2sensitivity=1 then
ts2sensitivitylong=close
ts2sensitivityshort=close
elsif ts2sensitivity=2 then
ts2sensitivitylong=high
ts2sensitivityshort=low
elsif ts2sensitivity=3 then
ts2sensitivitylong=low
ts2sensitivityshort=high
elsif ts2sensitivity=4 then
ts2sensitivitylong=typicalprice
ts2sensitivityshort=typicalprice
endif
if longonmarket then
if newsl=0 and ts2sensitivitylong-positionprice>=trailingstartlong*pipsize then
newsl = positionprice+trailingsteplong*pipsize
endif
if newsl>0 and ts2sensitivitylong-newsl>=trailingsteplong*pipsize then
newsl = newsl+trailingsteplong*pipsize
endif
endif
if shortonmarket then
if newsl=0 and positionprice-ts2sensitivityshort>=trailingstartshort*pipsize then
newsl = positionprice-trailingstepshort*pipsize
endif
if newsl>0 and newsl-ts2sensitivityshort>=trailingstepshort*pipsize then
newsl = newsl-trailingstepshort*pipsize
endif
endif
mypositionprice = positionprice
endif
if barindex-tradeindex>1 then
if longonmarket then
if newsl>0 then
sell at newsl stop
endif
if newsl>0 then
if low crosses under newsl then
sell at market
endif
endif
endif
if shortonmarket then
if newsl>0 then
exitshort at newsl stop
endif
if newsl>0 then
if high crosses over newsl then
exitshort at market
endif
endif
endif
endif
if longonmarket then
SET TARGET %PROFIT TPL
elsif shortonmarket then
SET TARGET %PROFIT TPS
endif
SET STOP %LOSS SL
Hi Khaled, without looking at the actual strategy, the first thing i notice is that using breakeven with that trail is an odd choice as the % trail already has a breakeven
(compare lines 108-115 with lines 195 – 200)
I only use the breakeven code in conjunction with the ATR trail, which does not have that component.
But even in that case, using besg = 0.01 would be impossible on the DJ as that would be only 3.5 points. The IG minimum is 10.
Lastly, ts2sensitivity = 3 is also an odd choice as that means that the low of the candle has to be above the breakeven level (when long). This is the hardest combination to achieve, esp with your settings means a v long wait for the trail to start. I normally use 2, (high/low)
esp with your settings means a v long wait for the trail to start
actually when i wrote that, I had mistaken your tpl/tps values for tsl/tss … but I would still recommend using ts2sensitivity = 2 (without the breakeven)
Thanks for your quick feedback.
I actually sensitivity = 3 was the result of the backtest. I kept the % trailing system only and removed all the rest. I’ll test.
Again Thank you!
sensitivity = 3 was the result of the backtest
you mean you optimized it, with values 1 – 4 ?
Exactly. I simulated values for tsl with ts2sensitivity (1 to 4), then tss with ts2sensitivity (1 to 4), and best result came out with ts2sensitivity = 3.
@nonetheless , I am learning and developing a few strategies and robertogozzi, Nicolas, GraHal have been helping me over the last few weeks. Very keen to get my strategy working on PRT and I hope to go through your template and adopt the code where relevant, test them and feedback. I appreciate that you are sharing this template to help new members.
@Khaled, can you share your latest code as I am not getting the same result as your screen shots.
@micquan, As I mentioned in my previous post, it was a test to check and understand how the Trailing Stop shared by nonetheless works. I didn’t update this particular “simple” strategy, as I’ll not use it. If you don’t get the same results, may be you didn’t use same TF or not same dates (start/end) or may be you picked the Dow 1pound, while I used Dow 1 euro. The idea behind my post was to understand why there is a big gap between actual performance and MFE and nonetheless explained that I was using two times breakeven system together with inappropriate choice of ts2sensitivity option.
Happy to discuss further and/or to help testing an idea.