Your Pine Script looked perfect on history, then acted strange live. Here’s why, and how varip and barstate.isconfirmed help. π
In this short (Pine Script v6 Advanced #1):
β’ Past bars run your script once. The live bar runs it on every price update.
β’ Before each live update, regular variables roll back to their last confirmed value.
β’ varip keeps a value between live updates, so you can count updates inside a bar.
β’ barstate.isnew is true on the first update of a new bar, so you can reset the counter.
β’ barstate.isconfirmed is true once a bar has closed, so you can act only on closed bars.
Copy the code (Tick Counter):
//@version=6
indicator(“Tick Counter”)
varip int ticks = 0
if barstate.isnew
ticks := 0
ticks += 1
plot(ticks, “Updates this bar”)
bgcolor(barstate.isconfirmed ? na : color.new(color.blue, 85))
What you’ll see: on history, every bar shows 1. On the live bar, the count climbs with each update, and the blue background marks the bar that hasn’t closed.
βΆ Next up: Part 2, Intrabar Data (data from other timeframes).
Disclaimer: For educational purposes only. Not financial advice. Trading involves substantial risk of loss.
π’ Join the Community:
πStart free at https://www.pinegen.ai/?utm_source=youtube&utm_medium=social&utm_campaign=landing-page
βοΈ Telegram: https://t.me/rangatechnologies
π’ Telegram Channel: https://t.me/PineGenAI
π¬ WhatsApp: https://api.whatsapp.com/message/XEABYADPSDL2D1
π¦ Twitter : https://x.com/PineGenAI
πΌ LinkedIn: https://www.linkedin.com/showcase/pinegen-ai/
πΈ Instagram: https://www.instagram.com/pinegenai
π Facebook: https://www.facebook.com/PineGenAi/
π΅ Tiktok: https://www.tiktok.com/@pinegenai
#PineScript #TradingView #PineGenAI #AITrading #NoCodePinescripts #TradingStrategy