I have coded this so that once the alarm fires, it sets the Bars count and shouldnèt trigger again for 5mins. However, when the lines cross, the a;larm keeps triggering every few ticks as the values cross and uncross. How can I stop this"
Make your test only on new bar by comparing closed candles.
If (isNewBar()) if (iMAOnArray(TSI_Buffer,0,7,0,MODE_EMA,1) < TSI_Buffer[1] && iMAOnArray(TSI_Buffer,0,7,0,MODE_EMA,2) > TSI_Buffer[2] ) { Comment ("Crossed up"); if (Bars>BarsTotal || BarsTotal==0) { Alert ("Crossing up"); BarsTotal=Bars; } Alert ("Crossing up"); } else if (iMAOnArray(TSI_Buffer,0,7,0,MODE_EMA,1) > TSI_Buffer[1] && iMAOnArray(TSI_Buffer,0,7,0,MODE_EMA,2) < TSI_Buffer[2] ) { Comment ("Crossed down"); if (Bars>BarsTotal || BarsTotal==0) { Alert ("Crossing down"); BarsTotal=Bars; } } }
Search the site if you need an implementation of isNewBar.
Make your test only on new bar by comparing closed candles.
Search the site if you need an implementation of isNewBar.
if I do that then it will only sound at the closing of a candle. If the cross happens halfway through a 5 min candle, the alert won't happen until 2.5 mins later. But I need the alert to happen as soon as it crosses
if I do that then it will only sound at the closing of a candle. If the cross happens halfway through a 5 min candle, the alert won't happen until 2.5 mins later. But I need the alert to happen as soon as it crosses
You have to choose what you want. If you need a "good" signal then wait for closed candle. If you can deal with a "false" alert then trigger it on open candle, but you signal can have disappeared when the candle will be closed.
To manage the latter, you can for example set a bool that alert has been triggered and reset this bool on new bar.
You have to choose what you want. If you need a "good" signal then wait for closed candle. If you can deal with a "false" alert then trigger it on open candle, but you signal can have disappeared when the candle will be closed.
To manage the latter, you can for example set a bool that alert has been triggered and reset this bool on new bar.
in the code above I set the barstotal flag but it doesn't stop the alarm
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have coded this so that once the alarm fires, it sets the Bars count and shouldnèt trigger again for 5mins. However, when the lines cross, the a;larm keeps triggering every few ticks as the values cross and uncross. How can I stop this"