PaulParticipant
Master
I have this running on us100 nasdaq 5 min tf. Was a few times about to close it, but let it run. Had the feeling live (demo) did a bit better then what I saw in the (bad) backtest.
So there’s a good 2 months of data. (ignore that it mentions dax).
//-------------------------------------------------------------------------
// Hoofd code : MLV DAX v3p 24h hull #2
//-------------------------------------------------------------------------
defparam cumulateorders = false
defparam preloadbars = 10000
TIMEFRAME (default)
once enablesl = 1 // stoploss
once enablept = 1 // profit target
once enablets = 1 // trailing stop atr
once displaysl = 0 // stop loss
once displaypt = 0 // profit target
once displayts = 0 // trailing stop atr
once positionweekend = 1 // weekend position then ignore time
once fridayclosetime = 225500
once tds=4
// settings
once positionsize = 1
once sl = 0.5
once pt = 2.0
// general
underlaying=100
// strategy
TIMEFRAME (15 minutes,updateonclose)
// MID-LEVEL 1
ml1 = (High[i] + Low[i]) / 2
// MID-LEVEL 2
Newhigh = 0
For i = 1 to 13 do
IF high[i] > Newhigh THEN
Newhigh = high[i]
ENDIF
NEXT
Newlow = 1000000000000
For i = 1 to 13 do
IF low[i] < Newlow THEN
Newlow= low[i]
ENDIF
NEXT
ml2 = (Newhigh + Newlow) /2
// MID-LEVEL 3
Newhigh = 0
For i = 1 to 4 do
IF high[i] > Newhigh THEN
Newhigh = high[i]
ENDIF
NEXT
Newlow = 1000000000000
For i = 1 to 4 do
IF low[i] < Newlow THEN
Newlow= low[i]
ENDIF
NEXT
TIMEFRAME (default)
// trend detection system
if tds=0 then
trendup=1
trenddown=1
else
if tds=1 then // 1 hour
trendup=(average[7](totalprice)>average[7](totalprice)[1])
trenddown=(average[1](totalprice)<average[1](totalprice)[1])
else
if tds=2 then
trendup=(Average[20](close)>Average[20](close)[1])
trenddown=(Average[35](close)<Average[35](close)[1])
else
if tds=3 then
period= 14
inner = 2*weightedaverage[round( period/2)](typicalprice)-weightedaverage[period](typicalprice)
hull = weightedaverage[round(sqrt(period))](inner)
trendup = hull > hull[1]
trenddown = hull < hull[1]
else
if tds=4 then
period= 14
inner = 2*weightedaverage[round( period/2)](totalprice)-weightedaverage[period](totalprice)
hull = weightedaverage[round(sqrt(period))](inner)
trendup = hull > hull[1]
trenddown = hull < hull[1]
endif
endif
endif
endif
endif
//
condbuy = ml1 crosses over ml2
condbuy = condbuy and close<close[1] and open<open[1]
condbuy = condbuy and trendup
condsell= ml1 crosses under ml2
condsell= condsell and close>close[1] and open>open[1]
condsell= condsell and trenddown
//
if condbuy then
buy positionsize contract at market
endif
if condsell then
sellshort positionsize contract at market
endif
// close position on friday
if positionweekend=0 then
if onmarket then
if currentdayofweek=5 and time>=fridayclosetime then
sell at market
exitshort at market
endif
endif
endif
//
if enablets then
//
once steps=0.05 // set to 0 to ignore steps
once minatrdist=3
once atrtrailingperiod = 14 // atr parameter
once minstop = 10 // minimum trailing stop distance
if barindex=tradeindex then
trailingstoplong = 4 // trailing stop atr distance
trailingstopshort = 4 // trailing stop atr distance
else
if longonmarket then
if newsl>0 then
if trailingstoplong>minatrdist then
if newsl>newsl[1] then
trailingstoplong=trailingstoplong
else
trailingstoplong=trailingstoplong-steps
endif
else
trailingstoplong=minatrdist
endif
endif
endif
if shortonmarket then
if newsl>0 then
if trailingstopshort>minatrdist then
if newsl<newsl[1] then
trailingstopshort=trailingstopshort
else
trailingstopshort=trailingstopshort-steps
endif
else
trailingstopshort=minatrdist
endif
endif
endif
endif
//
atrtrail=averagetruerange[atrtrailingperiod]((close/10)*pipsize)/1000
trailingstartl=round(atrtrail*trailingstoplong)
trailingstarts=round(atrtrail*trailingstopshort)
tgl=trailingstartl
tgs=trailingstarts
if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
maxprice=0
minprice=close
newsl=0
endif
//
if longonmarket then
maxprice=max(maxprice,close)
if maxprice-tradeprice(1)>=tgl*pointsize then
if maxprice-tradeprice(1)>=minstop then
newsl=maxprice-tgl*pointsize
else
newsl=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
newsl=minprice+tgs*pointsize
else
newsl=minprice+minstop*pointsize
endif
endif
endif
//
if longonmarket then
if newsl>0 then
sell at newsl stop
endif
endif
if shortonmarket then
if newsl>0 then
exitshort at newsl stop
endif
endif
//
if displayts then
//graphonprice newsl coloured(0,0,255,255) as "trailingstop atr"
endif
endif
// display profittarget
if enablept then
if not onmarket then
ptarget=0
elsif longonmarket then
ptarget=tradeprice(1) +((tradeprice(1) *pt)/underlaying)*pointsize
elsif shortonmarket then
ptarget=tradeprice(1) -((tradeprice(1) *pt)/underlaying)*pointsize
endif
set target %profit pt
if displaypt then
//graphonprice ptarget coloured(121,141,35,255) as "profittarget"
ptarget=ptarget
endif
endif
// set stoploss
if enablesl then
if not onmarket then
sloss=0
elsif longonmarket then
sloss=tradeprice(1) -((tradeprice(1) *sl)/underlaying)*pointsize
elsif shortonmarket then
sloss=tradeprice(1) +((tradeprice(1) *sl)/underlaying)*pointsize
endif
set stop %loss sl
if displaysl then
//graphonprice sloss coloured(255,0,0,255) as "stoploss"
sloss=sloss
endif
endif
indeed, before april 2019, it’s not good..
but if it’s in production, you believe in it
PaulParticipant
Master
quick look at this old one, on the dow 1m.
Added part of nonetheless setup and changed entry criteria.
Optimised roughly on 200k from july ’20 & compared to 1m and of-course data before 200k is poor with exception the months april-mei-june ’20
results atm are with no trailingstop or breakeven, no overnight/weekend, a relatively small stoploss & a slightly bigger profittarget.
defparam cumulateorders = false
defparam preloadbars = 2000
defparam flatbefore = 080000
once tradetype = 1 // [1]ls [2]l [3]s
once positionsize=1
once sll = 0.6 // stoploss long
once sls = 0.6 // stoploss short
once ptl = sll*1.4 // profittarget long
once pts = sls*1.4 // profittarget short
// time
ctime=openhour<21
TIMEFRAME (15 minutes)
indicator1 = SuperTrend[2,10]
indicator1a = SAR[0.015,0.015,0.02]
cnd1 = (close > indicator1) or (close > indicator1a)
cnd2 = (close < indicator1) or (close < indicator1a)
// MID-LEVEL 1
ml1 = (High[i] + Low[i]) / 2
// MID-LEVEL 2
Newhigh = 0
For i = 1 to 2 do
IF high[i] > Newhigh THEN
Newhigh = high[i]
ENDIF
NEXT
Newlow = 1000000000000
For i = 1 to 2 do
IF low[i] < Newlow THEN
Newlow= low[i]
ENDIF
NEXT
ml2 = (Newhigh + Newlow) /2
// MID-LEVEL 3
Newhigh = 0
For i = 1 to 7 do
IF high[i] > Newhigh THEN
Newhigh = high[i]
ENDIF
NEXT
Newlow = 1000000000000
For i = 1 to 5 do
IF low[i] < Newlow THEN
Newlow= low[i]
ENDIF
NEXT
ml3 = (Newhigh + Newlow) /2
TIMEFRAME (default)
max1=max(ml1,ml2)
max2=max(max1,ml3)
min1=min(ml1,ml2)
min2=min(min1,ml3)
// conditions
condbuy = ml1 > ml3 and ml1 crosses under ml2
condbuy = condbuy or (ml1 > ml2 and ml1 crosses under ml3) and cnd1
condbuy = condbuy and (max2-min2)>8
condsell= ml1 < ml3 and ml1 crosses over ml2
condsell= condsell or (ml1 < ml2 and ml1 crosses over ml3) and cnd2
condsell = condsell and (max2-min2)>2
// entry criteria
if ctime then
if tradetype=1 then
if not longonmarket and condbuy then
buy positionsize contract at market
set stop %loss sll
set target %profit ptl
endif
if not shortonmarket and condsell then
sellshort positionsize contract at market
set stop %loss sls
set target %profit pts
endif
elsif tradetype=2 then
if not longonmarket and condbuy then
buy positionsize contract at market
set stop %loss sll
set target %profit ptl
endif
elsif tradetype=3 then
if not shortonmarket and condsell then
sellshort positionsize contract at market
set stop %loss sls
set target %profit pts
endif
endif
endif
if dayofweek=5 and time>=215500 then
sell at market
exitshort at market
endif
PaulParticipant
Master
found this old one and used it for testing, dow 5m, 150k