Entry at Inside Bar High rupture
Posted: Mon Mar 21, 2022 4:13 pm
I'm learning to code and i'm having trouble to make my strategy.entry(long). I have some conditions to make the entry (inside bar above ema1 and ema2, ema1 above ema2), having them being met I would like to enter when the inside bar High is surpassed, but only if it is surpassed THE NEXT CANDLE by 20usd. My stop loss would be: the low of the candle before the inside bar less 20 usd. My target would be: 2 times my risk.
The script is partially working. The problem is that it is buying whenever it crosses the inside bar high + 20usd. Even if it is some candles after. I would like it to enter only if it's price is surpassed the next candle.
The script is partially working. The problem is that it is buying whenever it crosses the inside bar high + 20usd. Even if it is some candles after. I would like it to enter only if it's price is surpassed the next candle.
Code: Select all
inside = high < high[1] and low > low[1]
emalong = pema1 > pema2
long = low > pema1
longc = emalong and long and inside
entrylong = high + (200*10*syminfo.mintick)
stopL = low [1] - (200*10*syminfo.mintick)
targetL = ((2*(high - stopL))+high)*100*syminfo.mintick
var stopLossLongSaved = 0.0
var takeProfitLongSaved = 0.0
var stopLossShortSaved = 0.0
var takeProfitShortSaved = 0.0
longc = afterStartDate and inside and emalong and long
if longc
if strategy.position_size == 0
stopLossLongSaved := stopL
takeProfitLongSaved := targetL
strategy.entry('Long', strategy.long, stop = entrylong)
plot(longc ? stopL : na, color = color.red, style = plot.style_linebr)
plot(longc ? targetL : na, color = color.lime, style = plot.style_linebr)