Thinking in Pine - Execution Model and Rollback on Realtime Bars

BINANCE:BTCUSDT   Bitcoin / TetherUS
Hello All,

Welcome to another session of "Thinking in Pine" - short video tutorials on Pine Script.

Before continuing with this video, if you are not familiar with var, varip and regular variables, please watch our previous video - "Thinking in Pine - var, varip and regular variables"

🎲 Today's discussion points
  • How var, varip and regular variable modification code works with historical and real time bar updates.
  • Rollback concept of var variables

🎯 Example Program Used
// The statements execute on every tick
count = 0.0

varip varipcount = 0 //executes only once on the first bar
// Reset counter on every bar
// if(barstate.isconfirmed)
//     varipcount:=0

// Rollbacks and assigns on every tick
var varcount = 0.0 //executes only once on the first bar
// varcount:=varcount[1] -- Rollback
// varcount := varcount + 1 -- execute again

plot(varipcount, 'Varip Count')
plot(varcount, 'Var Count')
plot(count, 'Çount')

arrRegular =<float>()
var arrVar =<float>()
varip arrVarip =<float>()
if(bar_index >= last_bar_index -5)
    arrVarip.push(close)'Regular : {0}', arrRegular)'Var : {0}', arrVar)'Varip : {0}', arrVarip)

🎲 References
Pine Script® User Manual - Execution Model


The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.