OPEN-SOURCE SCRIPT

Repainting? Yes/No

已更新
Suppose, you'd like to avoid repainting issues in your scripts. How to achieve this?..

If you do not use `security` function, then simply calculate only on confirmed (closed) bars. Use either `close[1]` as a source or/and `barstate.isconfirmed` variable in your logic.

But if you use `security` to get data of a higher timeframe, then what? In such a case to get the same result - use `security` with
* `lookahead` param switched ON
* in `expr` param use "square brackets of 1" - previous bar value of your signal (`data` variable is your "signal").

NOTE 1: that `gaps` param doesn't affect repainting in any way.
NOTE 2: `lookahead` param when switched OFF affects the `security` behaviour only on history data. And indicator still repaints (realtime calculations change after chart reload).

In my example, script uses 5 minute closed bars (that means they will not change after chart reload, so there will be no repainting) on 1 minute chart.
Plots that "repaint" are hidden. You may make them visible to see how they look like.

發布通知
Just fixed comment
Oscillators

開源腳本

在真正的TradingView精神中,這個腳本的作者以開源的方式發佈,這樣交易員可以理解和驗證它。請向作者致敬!您可以免費使用它,但在出版物中再次使用這段程式碼將受到網站規則的約束。 您可以收藏它以在圖表上使用。

想在圖表上使用此腳本?

免責聲明