AbzParticipant
Veteran
Hello
looking for some help on the strategy below.
- upper is the highest price between 080000 and 090000
- enter short when price goes under “upper” but only if next bar closes under upper and high on this bar must also be below upper
- SL shoud be the amount of points between upper and lower in the timeframe 080000 – 090000
- profitt target shoud be lower from the time frame 080000 – 090000
- same goes for Long
- enter long when price goes under lower and next bar closes above lower and lowest of this bar is also above lowest.
- SL shoud be the amount of points between upper and lower in the timeframe 080000 – 090000
- profitt target shoud be upper from the time frame 080000 – 090000
DEFPARAM CumulateOrders = false // Cumulating positions
DEFPARAM PRELOADBARS = 1000
DEFPARAM FLATAFTER = 220000
IF Time = 080000 THEN
TradeCounter = 0
ENDIF
// Trading Hours
IF (Time >= 090000 AND Time <= t1) and dayofweek<=5 then// or (Time >= 220000 AND Time <= 220100) and dayofweek=1 THEN //
Tradetime=1
else
Tradetime=0
endif
t1=220000
//Settings
once upper=0
once lower=0
// calculate upper and lower
endtime = 090000
If Time = endtime then
upper=highest[12](high)
lower=lowest[12](low)
dif=round(abs((lower-upper)*pipsize*pointvalue))
endif
//looking for short position
entershort1 = close[1] > upper
entershort2 = close crosses under upper
entershort3 = close < upper
if not onmarket and entershort1 and entershort2 and entershort3 then
fadeshort=1
elsif onmarket then
fadeshort=0
endif
if not onmarket and tradecounter < 1 and tradetime and fadeshort then
sellshort 5 contracts at market
TradeCounter = TradeCounter + 1
endif
set stop loss dif
set target profit lower
Hi Abz, your code seems a bit “scrambled”, I think you did a lot of debugging and copy/paste 🙂
I changed a bit some of the lines and added some variables too (still only short position):
DEFPARAM CumulateOrders = false // Cumulating positions
DEFPARAM PRELOADBARS = 1000
DEFPARAM FLATAFTER = 220000
IF Time = 080000 THEN
TradeCounter = 0
ENDIF
// Trading Hours
t1=220000
tradetime=Time >= 090000 AND Time <= t1 and dayofweek<=5
// calculate upper and lower
endtime = 090000
If Time = endtime then
upper=highest[12](high)
lower=lowest[12](low)
dif=upper-lower
endif
//looking for short position
entershort= close[1] crosses under upper and high<upper and close<upper
if not onmarket and tradecounter < 1 and tradetime and entershort then
sellshort 5 contracts at market
tp = close-lower
TradeCounter = TradeCounter + 1
endif
set stop loss dif
set target profit tp
Please consider that I did not test this code, please do your own tests, thank you.
AbzParticipant
Veteran
Thanks Nicolas the code looks much better 🙂
for long will this work? i tried it and i dont get the entry points i am looking for.
//looking for Long position
enterlong= close[1] crosses over lower and low>lower and close>lower
if not onmarket and tradecounter < 1 and tradetime and enterlong then
buy 5 contracts at market
tp = close-upper
TradeCounter = TradeCounter + 1
endif
AbzParticipant
Veteran
hello
i am testing the strategy with short positions and i see that there are many trades that are executed that does not fulfill the criterias in the code see attached screen. any idea why?
Your upper and lower levels, are they correctly calculated? Did you GRAPH these variables in ProBacktest to see if they are ok?