Being always ON MARKET the MM part will never run as it is now, but you can replace IF NOT ON MARKET THEN with:
IF StrategyProfit <> StrategyProfit[1] THEN
because each time a trade is closed (no matter whether a new one is started at the same time), STRATEGYPROFIT is updated, so it will be different than it was the previous candle.
Another solution would be replacing IF NOT ONMARKET THEN with:
IF (LongOnmarket AND ShortOnMarket[1]) OR (LongOnmarket[1] AND ShortOnMarket)
which checks whenever a different positions has been entered (and the previous one closed).
I prefer the first solution.
This way you will be able to execute the MM part to manage the position size.
Anyone can run this on 200k?
DJI-1m
Could be too curve fitted, but interesting to see how it goes. Thanks in advance.
Defparam CumulateOrders = false
TIMEFRAME(5 minutes, updateonclose)
mac = MACD[8,6,4]
bull5 = mac > 0
bear5 = mac < 0
TIMEFRAME(2 minutes, updateonclose)
bull2 = Average[5] > Average[13]
bear2 = Average[5] < Average[13]
TIMEFRAME(default)
Period= 7
inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
HULLa = weightedaverage[round(sqrt(Period))](inner)
Periodb= 42
innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)
HULLb = weightedaverage[round(sqrt(Periodb))](innerb)
Periodc= 17
innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)
HULLc = weightedaverage[round(sqrt(Periodc))](innerc)
c1 = HULLb > HULLa
c2 = HULLb < HULLa
c3 = HULLb > HULLb[1]and HULLb[1]<HULLb[2]
c4 = HULLb < HULLb[1]and HULLb[1]>HULLb[2]
c5 = HULLc > HULLc[1]
c6 = HULLc < HULLc[1]
bull = c1 and c3 and c5 and bull5 and bull2
bear = c2 and c4 and c6 and bear5 and bear2
//Timeframe(default)
//Once BB = 20
//Once p = 54
//MaxbbUP = highest[p](BollingerUp[BB](close)) and bull
//MinbbDN = lowest[p](BollingerDown[BB](close)) and bear
//MyAdx = (summation[p](Adx[14] < 25) = p)
//If MyAdx then
//Buy 1 contract at MaxbbUP Stop
//Sellshort 1 contract at MinbbDN Stop
//Endif
//// Conditions to enter long positions
IF NOT LongOnMarket AND bull THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
//
//// Conditions to exit long positions
//If LongOnMarket AND YourConditions THEN
//SELL AT MARKET
//ENDIF
//
//// Conditions to enter short positions
IF NOT ShortOnMarket AND bear THEN
SELLSHORT 1 CONTRACTS AT MARKET
ENDIF
//
//// Conditions to exit short positions
//IF ShortOnMarket AND YourConditions THEN
//EXITSHORT AT MARKET
//ENDIF
// Stops and targets : Enter your protection stops and profit targets here
//SET STOP %LOSS 1
SET STOP pLoss 300
//SET TARGET pProfit 100
// trailing atr stop
once trailingstoptype = 1 // trailing stop - 0 off, 1 on
once tsincrements = .03//.05 // set to 0 to ignore tsincrements
once tsminatrdist = 1//3
once tsatrperiod = 14 // ts atr parameter
once tsminstop = 12 // ts minimum stop distance
once tssensitivity = 1 // [0]close;[1]high/low
if trailingstoptype then
if barindex=tradeindex then
trailingstoplong = 2 // ts atr distance
trailingstopshort = 2 // ts atr distance
else
if longonmarket then
if tsnewsl>0 then
if trailingstoplong>tsminatrdist then
if tsnewsl>tsnewsl[1] then
trailingstoplong=trailingstoplong
else
trailingstoplong=trailingstoplong-tsincrements
endif
else
trailingstoplong=tsminatrdist
endif
endif
endif
if shortonmarket then
if tsnewsl>0 then
if trailingstopshort>tsminatrdist then
if tsnewsl<tsnewsl[1] then
trailingstopshort=trailingstopshort
else
trailingstopshort=trailingstopshort-tsincrements
endif
else
trailingstopshort=tsminatrdist
endif
endif
endif
endif
tsatr=averagetruerange[tsatrperiod]((close/10)*pipsize)/1000
//tsatr=averagetruerange[tsatrperiod]((close/1)*pipsize) // (forex)
tgl=round(tsatr*trailingstoplong)
tgs=round(tsatr*trailingstopshort)
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
tsmaxprice=0
tsminprice=close
tsnewsl=0
endif
if tssensitivity then
tssensitivitylong=high
tssensitivityshort=low
else
tssensitivitylong=close
tssensitivityshort=close
endif
if longonmarket then
tsmaxprice=max(tsmaxprice,tssensitivitylong)
if tsmaxprice-tradeprice(1)>=tgl*pointsize then
if tsmaxprice-tradeprice(1)>=tsminstop then
tsnewsl=tsmaxprice-tgl*pointsize
else
tsnewsl=tsmaxprice-tsminstop*pointsize
endif
endif
endif
if shortonmarket then
tsminprice=min(tsminprice,tssensitivityshort)
if tradeprice(1)-tsminprice>=tgs*pointsize then
if tradeprice(1)-tsminprice>=tsminstop then
tsnewsl=tsminprice+tgs*pointsize
else
tsnewsl=tsminprice+tsminstop*pointsize
endif
endif
endif
if longonmarket then
if tsnewsl>0 then
sell at tsnewsl stop
endif
if tsnewsl>0 then
if low crosses under tsnewsl then
sell at market // when stop is rejected
endif
endif
endif
if shortonmarket then
if tsnewsl>0 then
exitshort at tsnewsl stop
endif
if tsnewsl>0 then
if high crosses over tsnewsl then
exitshort at market // when stop is rejected
endif
endif
endif
endif
That’s indeed overfitted over the last 100k bars.
Thanks @Nicolas.
I thought so 🙂
Anyone have any inputs how it can be improved further?
Prolly optimization expert @nonetheless ?