Reputation: 13
I converted an Oscillator with false overlay into a buy/Sell arrows indicator but when I watch and wait patiently for a signal to appear at a crossover, it won't unlesss my android screen light goes off, and when I put it back on, I'll see a new signal about 3 to 4 bars further from where it was supposed to be printed, then later when tradingview app update data, the signal returns exactly to the point where it was supposed to be printed.
This is the plotshape line with crossover/crossunder condition:
buy = crossover(rsi, ci)
sell = crossunder(rsi, ci)
plotshape(buy, style=shape.arrowup, location=location.belowbar, text="Buy", size=size.normal, color=lime, transp=0)
plotshape(sell, style=shape.arrowdown, location=location.abovebar, text="Sell", size=size.normal, color=red, transp =0).
I expected the signal to be printed at the exact point of crossover, not 3 to 4 bars away and later returning to the point where the crossover happened. I still do not understand what's going on. Is it a problem of data update from the app, because my account has not been upgraded yet?
Upvotes: 0
Views: 108
Reputation: 21332
You are describing what repainting is. Ideally, you should wait until the bar is closed to make a decision. You can do that by adding barstate.isconfirmed
to your condition.
Historical data does not include records of intermediary price movements on bars; only open, high, low and close values (OHLC).
On realtime bars (bars running when the instrument’s market is open), however, the high, low and close values are not fixed; they can change values many times before the realtime bar closes and its HLC values are fixed. They are fluid. This leads to a script sometimes working differently on historical data and in real time, where only the open price will not change during the bar.
Any script using values like high, low and close in realtime is subject to producing calculations that may not be repeatable on historical bars — thus repaint.
This happens when you force re-execution of the script (refersh the page, restart the app etc.).
Upvotes: 0