It’s getting late … that’s probably why I don’t see the error.
The following problem with this test system:
I created it as a breakout MTF, breakout from the M15 chart with the data from the M30 chart. So far it works according to my ideas. But … if I switch to the M3 chart now to add a trailing stop … my breakouts will no longer work. Unfortunately I cannot find the error. Can someone help me please?
//================================================
DEFPARAM CUMULATEORDERS = false
defparam preloadbars = 5000
//daysForbiddenEntry = OpenDayOfWeek = 5 and time >= ti
//Risk Management
PositionSize=1
//timeframe(4hour, updateonclose)
////MACDLiniex = MACDline[12,26,9](close) > 0
//MAxx = Average[15,1](typicalprice)
//mylongx = MAxx > MAxx[1]
timeframe(30minute, updateonclose)
//MA25 = Average[25,1](close) //Exponential
MA50 = Average[50,1](close) //Exponential
MA100 = Average[100,1](close) //Exponential
MA150 = Average[150,1](close) //Exponential
MA180 = Average[180,1](close) //Exponential
//timeframe(30minute, updateonclose)
////MACDLiniex = MACDline[12,26,9](close) > 0
//MAxx = Average[100,1](close) //typicalprice
//mylongx = MAxx > MAxx[1]
//timeframe(15minute, updateonclose)
per = 200 //20 200
MA = Average[per,1](close) //close typicalprice
//MA150 = Average[150,1](close) //Exponential
//MA180 = Average[180,1](close) //Exponential
MA5 = Average[5,1](close) //Exponential
MA10 = Average[10,1](close) //Exponential
MA21 = Average[21,1](close) //Exponential
MA34 = Average[34,1](close) //Exponential
MA55 = Average[55,1](close) //Exponential
MA89 = Average[89,1](close) //Exponential
mylong = MA > MA[1]
mylong2 = MA100 > MA150 and MA150 > MA180 and MA50 > MA100 //and MA25 > MA50
mylong3 = MA21 > MA34
mylong4 = MA34 > MA55
mylong5 = MA55 > MA89
mylong6 = close > MA5
mylong7 = MA5 > MA10 and MA10 > MA21 and MA21 > MA21[1] and MA10 > MA10[1]
mylong8 = close > MA
//Volaititätfilter
AvgRange = average[20,0](range)
TradeOFF = range > (AvgRange * 3) //no trading if the current range > twice its average //3
//Breakout
Hoch = highest[10](high) //8
timeframe(15minute, updateonclose)
Breakout = close crosses over Hoch[1] //and close[1] > Hoch[2]
// trading window
ONCE BuyTime = 50000
ONCE SellTime = 210000
// position management
IF Time >= BuyTime AND Time <= SellTime THEN
If Breakout and mylong3 and mylong4 and mylong5 Then
Buy PositionSize CONTRACTS AT MARKET
SET STOP %LOSS 0.9
SET TARGET %PROFIT 1
ENDIF
endif
timeframe(default)
////////////////////////////////////////////////////
//// %trailing stop function incl. cumulative positions
//once trailingstoptype = 1
//if trailingstoptype then
////====================
//trailingpercentlong = start // %
//trailingpercentshort = 0.2 // %
//once acceleratorlong = step // typically tst*0.1
//once acceleratorshort= 0.05 // 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
//////////////////////////////////////////////////////////////////
Hello phoentzs,
Quite late, yes. Or early !
TradeOFF = range > (AvgRange * 3) //no trading if the current range > twice its average //3
I am sure this is too simple … but if this line determines when not to trade, and your comments speaks of twice while the code does trice … who knows.
Edit : Never mind, because you don’t use that variable.
It is a trial code, so many variables are not used. I’m building the strategy with a few things from my construction kit. Add the system to the M15 chart and it will work perfectly as it should. But if you switch to the M3 or M5 or M1 chart, it should actually work. But it doesn’t. The question is why? Something is wrong with the MTF instructions. I believe.
Try increasing the number of units used in your default TF.
Could you please try the system to find out why it doesn’t convert the inputs to lower TF?
JSParticipant
Senior
Try removing “UpdateOnClose” in the timeframes.
Explained again in words: The Trend and Highest [10] high come from the M30-TF. The close comes from the M15-TF. In the TF M15 it works as it should. But now I want to add a trailing stop to the M3 with this system structure … When switching to TF M3, it is noticeable that the system structure no longer works. Instead of several 100 entries, I only have 10 or 20 in the same period.
@JS Why? I can’t test it now, but my MTF systems actually all work with “update onclose” …
JSParticipant
Senior
When you remove “UpdateOnClose” it shows the trades again (not sure why)
Could you please try the system to find out why it doesn’t convert the inputs to lower TF?
Did you try increasing the units?
A couple of variables are not defined, Start and Step.
The trailing stop is still commented out, first only SL / TP … JS says it works without “Updateonclose”. But why without? Does that change the logic of the system?
I would change line 59 to
timeframe (default)
The 15 min TF seems redundant if you’re going to run it on 3min
The “Close” from M15 is faster than the “Close” from M30 … that was actually the point of the matter … at least it seems logical to me. Similar to my H4 breakout. Do you remember nonethless?
JSParticipant
Senior
If you change nothing in the original code except replace “Crosses Over” by “>” then the trades show also in a 3 minute TF (again not sure why)