Once per bar alert: Difference between revisions
From MultiCharts
no edit summary
(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...") |
No edit summary |
||
Line 28: | Line 28: | ||
end; | end; | ||
</syntaxhighlight> | |||
== Triggering an alert once per bar - simplified == | |||
To simplify the triggering of an alert once per bar, and not clutter your code with the code logic from the example above, consider making a function called '''AlertOncePerBar''' (Return type: Numeric, Function Storage: Simple), in which you'll place the following code: | |||
<syntaxhighlight> | |||
{ | |||
AlertOncePerBar function; will generate an alert once per bar. | |||
} | |||
Inputs: | |||
AlertText(StringSimple); | |||
Variables: | |||
IntraBarPersist barNumOfAlert(0); | |||
if (CurrentBar <> barNumOfAlert) then begin | |||
Alert(AlertText); | |||
barNumOfAlert = CurrentBar; | |||
end; | |||
AlertOncePerBar = 0; // dummy | |||
</syntaxhighlight> | |||
Now, if you want to call an alert once per bar (for example, with an EMA crossover), you can call that with: | |||
<syntaxhighlight> | |||
if (XAverage(Close, 5) crosses above XAverage(Close, 20)) then | |||
AlertOncePerBar("EMA cross alert"); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:About_EasyLanguage]] | [[Category:About_EasyLanguage]] |