PDA

View Full Version : How to play alert sound only once



lepugmo
07-05-2016 04:31, 04:31 AM
I have some indiors where an arrow becomes painted on the chart once standards I define occurs. Instead of simply staring at MT4 all day , I'd prefer an alert to play when the arrow becomes attracted so I could do other work on my PC. BUT, I just want the alert to play only once! How do I create this so?

The basic code I used in my indiors to play the awake is:

Inserted Code PlaySound(Alert.wav);

Thanks.

lepugmo
11-16-2021 03:53, 03:53 AM
quote the default Alert.wav is too brief duration and frequently missed. Use a music wav file of several seconds, example 30 seconds. // play audio wav file extern bool PlaySounds = true; //. . .false; // wave file to be performed extern string AlertSound = music.wav; if(PlaySounds)PlaySound(AlertSound); *** create a wav file from a favorite music piece and title which music.wav Thank you but my question is more about how to stop the alert getting played .

alelau93
11-16-2021 05:13, 05:13 AM
It is dependent upon how your awake is becoming triggered, but a couple of common ways to deal with this problem are:

1. Check for change of condition.
Use a static variable to keep in mind whether the previous run through OnCalculate() / OnTimer() resulted in an alert.
When it did, don't awake again.
When it did not, and this time has resulted in an alarm, then play the sound.
Inserted Code static bool OldState = false; bool NewState = (Close#91;1#93; gt; Close#91;two #93;-RRB-; // change for your logic if(! OldState NewState) PlaySound(Alert.wav); OldState = NewState;
2. Insert a time delay between alerts
Remember when the awake last triggered, put in a time delay to this (in seconds), then check that TimeCurrent() is greater than this time before enjoying the awake again.
Inserted Code static datetime LastAlert=0; if(Close#91;1#93; gt; Close#91;two #93; TimeCurrent() gt; LastAlert 300) // Change to your logic PlaySound(Alert.wav); LastAlert = TimeCurrent();
Or, you may use a combination of them both (when price is e round the brink of your alarm ).

Or, simply check once per bar.

Hope that helps

shaqlale
11-16-2021 06:34, 06:34 AM
I've some indiors where an arrow gets painted on the chart when criteria I define occurs. Instead of simply staring in MT4 all day long, I'd like an alert to play when the arrow gets attracted so I can do other work in my PC. BUT, I need the alert to perform once! How do I create this so? The simple code I used in my indiors to perform the alert would be: PlaySound(Alert.wav); Thanks.
The default Alert.wav is too brief duration and frequently missed.

Use a music wav file of many seconds, example 30 seconds.

// play music wav file
extern bool PlaySounds = true; //. . .false;
// wave file should be played
extern string AlertSound = music.wav;

if(PlaySounds)PlaySound(AlertSound);

*** produce a wav file from a favorite music slice and name that music.wav