Once per Bar Alert
From MultiCharts
With the Alert PowerLanguage keyword it's possible to trigger alerts every bar close or on every tick. But what if you want to trigger an alert once per bar?
Triggering an alert once per bar
The code example below will trigger an alert once per bar, even if the alert properties (in the Alert tab from the Format Indicator screen) are set to 'Alert Conditions Check - Every Tick'.
Variables:
IntraBarPersist alertAlreadyGiven(False);
if (CheckAlert = True) then begin
// Trigger an alert if the price goes higher than
// the highest high of the previous 10 bars.
if (alertAlreadyGiven = False) and (Close > Highest(High, 10)[1]) then begin
Alert(Text("The price, ", NumToStr(Close, 2), ", has crossed the highest high (",
NumToStr(Highest(High, 10)[1], 2), ") of the last 10 bars."));
// Set the boolean to true to prevent another alert
// on this bar.
alertAlreadyGiven = True;
end;
// Reset the boolean variable so that an alert can
// be triggered during the next bar.
if (BarStatus(1) = 2) then
alertAlreadyGiven = False;
end;