Play sound only once per bar

 

Hi,

i use a bar close timer which prints for example 1:45 (means 1 Min (m) 45 Sec (s) left until bar close).

What I'm trying to do is play once a sound if m<1 && s<40 for example. Two problems

1) MetaTrader only changes the bar close timer if there is a price printed

-> Ok, not good but I can live with that!

2) The code I have now is something like this

if(m<1 && s<40) { PlaySound("alert2.wav"); }

...so I get this sound alert for every price printed in that 40 seconds period.

How can I check if there was already a sound alert in that 40 seconds period, if yes don't play a sound again until next bar starts (m>1)?

Thanks

 

I can not help you but may give some links to Codersguru article and the threads where people were thinking about it aready:

- Alert once: https://www.mql5.com/en/forum/172885

- Alerts: many functions and examples https://www.mql5.com/en/forum/173092

- Easy iCustom and Alerts: https://www.mql5.com/en/forum/173589

- How to alert only at candle close: https://www.mql5.com/en/forum/general

 
newdigital:
- Alert once: https://www.mql5.com/en/forum/172885

Thanks a lot... that gaves me the needed hint

Reason: