How to play alert sound only once
Results 1 to 4 of 4

Thread: How to play alert sound only once

  1. #1
    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.

  2. #2
    Quote Originally Posted by ;
    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 .

  3. #3
    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

  4. #4
    Quote Originally Posted by ;
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.