Considering a 5 Minute Time Frame, adding two indicator to the chart - Test Indicator
and Test Strategy
- before the close of the Candle.
barstate.islast
is Falsebarstate.islast
is false for the last bar in Strategy
, while it is true for Indicator
.
Indicator Example
//@version=5
indicator("Test Indicator", overlay=true)
plotchar(barstate.islast, "islast", "", location = location.top, size = size.tiny)
Strategy Example
//@version=5
strategy("Test Strategy", overlay=true)
plotchar(barstate.islast, "islast", "", location = location.top, size = size.tiny)
After the close of the 5 Minute Candle, the value barstate.islast
is the same for Indicator
and Strategy
, even for the Last and Current Candle.
We can get the same behavior adding calc_on_every_tick = true
for the strategy.
Why the different behavior for bartstate.islast
, between Strategy
and Indicator
, where bartstate.islast
is false
for Strategy
, before the close of the last candle?
By default, strategies are calculated when the bar is closed. That's why it returns false
when it is an active bar because your strategy is not being executed on every tick.