Once per bar alert

From MultiCharts
Revision as of 05:47, 9 February 2012 by JoshM (talk | contribs) (Created page with "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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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;