When does Alert.BAR fire?
Alert.BAR gives a local alert at most once per bar when its condition is true. In the example script, close on the forming bar can update with a new quote. The condition checks whether the current value is above the level, so it can fire while the bar is forming. It can also fire on successive bars that stay above the level. A crossing condition adds a comparison with the earlier value.
In the fictional chart, A covers 10:00–10:05 a.m. ET. It trades up to 6,000.75 and closes at 5,999.75. A live above-level alert can qualify during A. A rule that requires a completed close above 6,000.00 fails for A. The candle high proves price went above the level in this exercise. It does not give the exact alert timestamp.
B covers 10:10–10:15 a.m. ET and closes at 6,000.50. The preceding bar closed at 5,999.50. On the next bar, close[1] is B and close[2] is the candle before it, so a completed-close cross qualifies. Record the condition bar separately from the time thinkorswim evaluates it or delivers the message.
A price touch and a confirmed close
Synthetic MES 5-minute candles. Times are bar closes in ET.
A trades above 6,000.00 and closes below it. B closes above it after the preceding bar closed below. The completed-close condition first qualifies when the next bar starts evaluating.
Local chart study that checks the developing bar
input level = 6000.00;
def above = close > level;
Alert(above, "Price above level", Alert.BAR, Sound.Ding);