Login Page - Create Account

Support Board


Date/Time: Fri, 07 Feb 2025 18:18:52 +0000



[Programming Help] - Alert when price is crossing / touching a Moving average

View Count: 1746

[2022-03-18 19:33:13]
User837393 - Posts: 135
Hello,
I'm building a simple alert in a Color Bar based on alert condition study so that the bar changes color as soon as it touch or cross a moving avereage. Eventualy I'm planing on using this to trigger trades.

Knowing that my MA is ID7.SG1, will this formula applies in the color bar based on alert condition :
=OR (CROSSFROMABOVE(LASTTRADE, ID7.SG1), CROSSFROMBELOW (LASTTRADE, ID7.SG1))

I'm not looking for the O H L C ... but I want the alert to happen immediately as soon as the price reaches the MA.
[2022-03-18 21:47:01]
Sawtooth - Posts: 4173
will this formula applies in the color bar based on alert condition
No, because the LASTPRICE is for the current bar only, and the comparison is to the previous bar.
The Close price is actually the last price in the current bar and the closed price in previous bars.

You need to use the Close instead of the LASTPRICE:
=OR (CROSSFROMABOVE(C, ID7.SG1), CROSSFROMBELOW (C, ID7.SG1))

If 'Evaluate On Bar Close' is not checked, you'll get an alert immediately as soon as the price reaches the MA.
You will probably want to check 'Alert Only Once Per Bar'.

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account