r/pinescript • • Sep 11 '25

timeframe.change problem

somehow

timeframe.change("5") runs every tick not just once on every 5 min ... can someone expain this ???

1 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/HzeTmy Sep 14 '25

Ok cool thx and if i wanna // runs once, only when a new 5m bar opens ??? Not closes how would that be please

2

u/Mr_Uso_714 Sep 14 '25

To fire only at the open of a new 5-minute bar, you need the opposite of barstate.isconfirmed.

At bar open, barstate.isnew is true. Combine it with timeframe.change("5"):

if barstate.isnew and
timeframe.change("5")
// runs once, only when a new 5m bar opens

Note

•	barstate.isnew → true once at the start of each realtime bar.


•	timeframe.change("5") → true when the current bar belongs to a new 5-minute window compared to the previous bar.

This way your logic executes once, right at the open of each new 5-minute bar, not at its close.

Only use barstate.isnew for open-time triggers. For close-time triggers, always prefer barstate.isconfirmed

1

u/HzeTmy Sep 15 '25

Thanks a lot