As seen in the picture below, the trade was initiated one bar after the desired bar. The black arrow indicates the right order place ( open of that day) but for some reason the trade was initiated only on the bar afterward ( blue arrow). How can I solve this problem?
attached is the picture :
Attached is the code:
//@version=5
strategy("Gap MSFT", overlay=true)
MSFT_close = request.security("MSFT", "D", close[1])
MSFT_open = request.security("MSFT", "D", open[0])
price_change = MSFT_open / MSFT_close > 1.03
if price_change
l = label.new(bar_index, na, str.tostring(MSFT_close),
color=color.green,
textcolor=color.rgb(255, 255, 255),
style=label.style_arrowup,
yloc=yloc.abovebar)
d = label.new(bar_index, na, str.tostring(MSFT_open),
color=color.rgb(86, 76, 175),
textcolor=color.rgb(255, 255, 255),
style=label.style_arrowdown,
yloc=yloc.belowbar)
if price_change
strategy.entry("long", strategy.long, 100)
strategy.exit("Exit Long", from_entry="long", limit=MSFT_open * 1.01)
bgcolor(price_change ? color.new(#c1defa, 51) : na)