pine-scriptpine-script-v5

barstate.isrealtime wrongly returns true in replay mode


I check to see if the chart is in replay mode and set a candle offset because I only want to include completed bars.

From my understanding barstate.isrealtime is meant to accomplish this. However when I go to replay mode for the first time I get barstate.isrealtime returning false as expected but the as soon as I go forward one bar it returns true. This is surely not correct. When in replay mode I would imagine all bars are historical?

// If Chart is realtime offset candle counts
//So not to include live bar
if (barstate.isrealtime)
    candle_offset := 1
else
    candle_offset := 0

Solution

  • You cannot determine if the chart is in replay mode. This is not possible.

    barstate.isrealtime will return true if it is a live bar. When you add your script to your chart, it will be false. As soon as the price moves, it will be true.

    Bar replay mode simulates the real-time. When you hit the "forward" the price moves as if it was real-time. Therefore, you will get true in bar replay mode too.