So weit bin ich heute nicht. Ich denke, M3 auch, oder M2 würde auch funktionieren. Gleicher Zeithorizont, nur schneller. Die Langversion von M3 funktioniert am besten an der Nasdaq. M1 auf SP500 und Dax. Ich habe Dow Jones noch nicht ausprobiert.
I’m not that far today. I think M3 too, or M2 would work too. Same time horizon, only faster. The long version of M3 works best on the Nasdaq. M1 on SP500 and Dax. I haven’t tried Dow Jones yet.
@nonethless: Sorry, I misspelled you.
I Combined Phonetzs code and made a long/short-version
How to make i better?
//Break-H4 Nasdaq M3
//================================================
DEFPARAM CUMULATEORDERS = false
defparam preloadbars = 5000
//Risk Management
PositionSize=1
timeframe(4hour, updateonclose)
barCount = barIndex
c1 = high
D1 = low
c2 = (Close > Open) //green
c3 = (Close < Open) //red
c4 = (high < high[1])//lowerhigh
c5 = (high > high[1])//higherhigh
//MACDLiniex = MACDline[12,26,9](close) > 0
MA5xx = Average[3,1](typicalprice) //close
MA10xx = Average[10,1](typicalprice) //close
MA15xx = Average[15,1](typicalprice) //15,1 close
mylongx = MA15xx > MA15xx[1] //and MA5xx > MA15xx// and MA10xx > MA15xx
MA5xxs = Average[19,1](typicalprice) //close
//MA10xx = Average[m2,1](typicalprice)
MA15xxs = Average[20,1](typicalprice) //15,1...40,6 close
//MA100xx = Average[m3,1](typicalprice) //close
myshortx = MA15xxs < MA15xxs[1] and MA5xxs < MA15xxs //and MA10xx < MA15xx
//mylongx2 = MA100xx > MA100xx[1]
shortcond = myshortx
timeframe(default)
once tradeOn = 1
if intradayBarIndex = 0 then
tradeOn = 1
endif
tradeBar = barCount
if not onMarket and tradeBar<>tradeBar[1] then
tradeOn = 1
endif
//Volaititätfilter
AvgRange = average[20,0](range)
TradeOFF = range > (AvgRange * 3) //no trading if the current range > twice its average //3
//myshort = MA < MA[1]
// trading window
ONCE BuyTime = 080000
ONCE SellTime = 215500
// position management
IF Time >= BuyTime AND Time <= SellTime THEN
If not onmarket and close crosses over c1 and mylongx and c3 and tradeOn Then //and not c5
Buy PositionSize CONTRACTS AT MARKET
SET STOP %LOSS 0.9 //100
SET TARGET %PROFIT 1 //125
tradeOn = 0
ENDIF
If not onmarket and close crosses over c1 and mylongx and c2 and tradeOn Then //and not TradeOFF and c3 close crosses over c1
Buy PositionSize CONTRACTS AT MARKET
SET STOP %LOSS 0.8 //100
SET TARGET %PROFIT 1 //125
tradeOn = 0
ENDIF
If not onmarket and close crosses under D1 and shortcond and tradeOn Then
sellshort PositionSize CONTRACTS AT MARKET
SET STOP %LOSS 0.7 //0.8
SET TARGET %PROFIT 0.8 //1
tradeOn = 0
ENDIF
endif
if time = 220000 and dayofweek=5 and (PositionPerf * PositionPrice / PipSize) >= 5 then //
sell at market
exitshort at market
endif
////////////////////////////////////////
// %trailing stop function incl. cumulative positions
once trailingstoptype = 1
if trailingstoptype then
//====================
trailingpercentlong = 0.32 // %
trailingpercentshort = 0.55 // %
once acceleratorlong = 0.015 // typically tst*0.1
once acceleratorshort= 0.025 // typically tss*0.1
ts2sensitivity = 2 // [1] close [2] high/low [3] low/high [4] typicalprice
//====================
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 then
newsl = positionprice+trailingsteplong + 0.2
endif
if newsl>0 and ts2sensitivitylong-newsl>=trailingsteplong then
newsl = newsl+trailingsteplong
endif
endif
if shortonmarket then
if newsl=0 and positionprice-ts2sensitivityshort>=trailingstartshort then
newsl = positionprice-trailingstepshort
endif
if newsl>0 and newsl-ts2sensitivityshort>=trailingstepshort then
newsl = newsl-trailingstepshort
endif
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
mypositionprice = positionprice
endif
if (shortonmarket and newsl > 0) or (longonmarket and newsl>0) then
if positioncount > positioncount[1] then
if longonmarket then
newsl = max(newsl,positionprice * newsl / mypositionprice)
endif
if shortonmarket then
newsl = min(newsl,positionprice * newsl / mypositionprice)
endif
endif
endif
//////////////////////////////////////////////////////////////
Mein Plan wäre, beide Versionen, lang und kurz, einzeln laufen zu lassen. Ohne eine Vollversion daraus zu machen.
My plan would be to run both versions, long and short, individually. Without making a full version out of it.
@phoentzs
Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.
Thank you 🙂
Maybe one more question for the great masters … Nicolas? Robertogozzi? If you manage entries from large time units with a trailing stop … which TF is best used for this? M1… 5? Is more data history better or faster reaction to a trailing stop?
I usually use 5-minute or 10-minute TFs for the trailing stop, mainly because they grants more data history, compared to smaller TFs.
I made a quick attempt to add short to this but it didn’t seem worth it, I’ll have another try when I get time.
This is a minor revision to my long version, trying to get the DD as low as poss (positionsize = 0.5)
These are the key changes:
timeframe(4 hour, updateonclose)
H4 = high
MA = Average[p,t](close)
cb1 = MA > MA[1]
timeframe(15 minutes)
mb = average[p1,t1](typicalprice)
cb4 = mb > mb[1]
timeframe(default)
ST = SuperTrend[m,n]
STa = SAR[q,w,e]
cb2 = (close > ST) or (close > STa)
cb3 = close crosses over H4
an impressive piece of work, nonetheless.
What if it would be possible to make a long/short version of this algo 🙂
You can have a go if you have time to crunch the numbers. The core of it would look like this:
timeframe(4 hour, updateonclose)
H4 = high
L4 = Low
MA = Average[p,t](close)
cb1 = MA > MA[1]
MAs = Average[p2,t2](close)
cs1 = MAs < MAs[1]
timeframe(15 minutes)
mb = average[p3,t3](typicalprice)
cb2 = mb > mb[1]
mbs = average[p4,t4](typicalprice)
cs2 = mbs < mbs[1]
timeframe(default)
ST = SuperTrend[m,n]
STa = SAR[q,w,e]
cb3 = (close > ST) or (close > STa)
cs3 = (close < ST) or (close < STa)
cb4 = close crosses over H4
cs4 = close crosses under L4
If you haven’t used this syntax before
Average[p,t]
the ‘t’ represents the type of MA, can be 0 – 8
‘p’ I usually optimize from 5 – 50 in steps of 5
(apologies if you know this already 😁)
Thanks alot for the input nonetheless. I made an attempt for long/short-version.
Do u guys see any improvements? nonetheless, robertogozzi, phoentzs?
I want to get rid of the big drawdown in december 2021.
Backtest with Size 0.5
CUMULATEORDERS = false
In the itf both the % trail and ATR trail are active, which one did you want to use?
Using both gets better results then just one when i backtested
I am not sure if the idea is a good one. Isn’t that what affects each other? Unfortunately, due to the sudden drop in the Nasdaq over the last few days, the SL had to take action. That’s why the last few days lost in long mode. I personally help myself with this by splitting the risk over several systems. In that case I use half a position in TF M3 and a half position in TF M1. M1 made a profit from the faster trailing stop, M3 a loss.
that sounds weird to me, I think there will be conflicts in the code, I’ll have a closer look at it later.