How to SendMail only once when conditions are met???
Page 1 of 842 12 LastLast
Results 1 to 10 of 15

Thread: How to SendMail only once when conditions are met???

  1. #1
    Given the following, hypothetically of course:

    //P ------------------------------------------------------------------
    //| ALERT.mq4 |
    //| Copyright � 2006, MetaQuotes Software Corp.. |
    //| http://www.metaquotes.net |
    // ------------------------------------------------------------------
    #property copyright Copyright � 2006, MetaQuotes Software Corp..
    #property hyperlink http://www.metaquotes.net

    #property indior_chart_window


    // ------------------------------------------------------------------
    //| Custom indior initialization function |
    // ------------------------------------------------------------------

    int init()

    return(0);

    // ------------------------------------------------------------------
    //| Custom indior deinitialization function |
    // ------------------------------------------------------------------
    int deinit()

    //--

    //--
    return(0);

    // ------------------------------------------------------------------
    //| Custom indior iteration function |
    // ------------------------------------------------------------------

    int begin ()


    dual Near = iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0);
    dual PriceNow = Bid;

    if (PriceNow gt; Near)


    SendMail(Out Of FX Data,Price gt; 15EMA!!!) ;


    else if (PriceNow lt; Near)


    SendMail(Out Of FX Data,Price lt; 15EMA!!!) ;


    return(0);



    This will send an alert email when the price is greater than the 15EMA. This is not the actual code of course it's only an example. I am guessing I need an assortment in here someplace to count how many times that alert will be sent when the condition(s) is met. I am still not up the variety mql chapter. . .This leads to another question, if the email is to be sent just after, would the indior need to get loaded on the chart again to become busy again? What I would really like is the email to be routed and a message box appear telling me to'Click OK to reload indior without having to drag it back on the chart window again...

  2. #2
    Utilize a script for this. The whole notion of script is running something and exit.

  3. #3
    Try something like That:

    int start()

    double Near = iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0);
    double PriceNow = Bid;
    bool UpAlerted = false;
    bool DnAlerted = false;

    if (PriceNow gt; Close )

    if (UpAlerted==false)

    SendMail(Out Of FX Data,Price gt; 15EMA!!!);
    UpAlerted = true;
    DnAlerted = false;


    else if (PriceNow lt; Close )

    if (DnAlerted==false)

    SendMail(Out Of FX Data,Price lt; 15EMA!!!) ;
    UpAlerted = false;
    DnAlerted = true;


    return(0);

  4. #4
    Quote Originally Posted by ;
    Try something like that:

    int begin ()

    double Near = iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0);
    dual PriceNow = Bid;
    bool UpAlerted = false;
    bool DnAlerted = false;

    if (PriceNow gt; Near)

    if (UpAlerted==false)

    SendMail(Out Of FX Data,Price gt; 15EMA!!!) ;
    UpAlerted = true;
    DnAlerted = false;


    else if (PriceNow lt; Near)

    if (DnAlerted==false)

    SendMail(Out Of FX Data,Price lt; 15EMA!!!) ;
    UpAlerted = false;
    DnAlerted = true;


    return(0);
    in order for this to work you need at least announce UpAlerted and DnAlerted as statics. When restarting MT4 but then, you will sync. Writing them as global would solve it, but is a way to reset the alert.

  5. #5
    OK:

    I made it a script but once again I can't find the error of my ways. What this is'supposed to do' is the following...

    When price is above the 89 smoothed moving average AND the 8ema gt; 21ema AND the gap between the 8ema and also the 21ema gt; 0.0002 AND the current bid equals the 15ema an alert sounds and an email is sent.

    Opposite for your Brief alert.

    It compiles fine and I watched these conditions become fulfilled three times yesterday (to get a bull alert) but the script didn't do anything.

    Can I missing something???

    // ------------------------------------------------------------------
    //| TCSCRIPTALERTv1.mq4 |
    //| Copyright � 2006, MetaQuotes Software Corp.. |
    //| http://www.metaquotes.net |
    //p ------------------------------------------------------------------
    #property copyright Copyright � 2006, MetaQuotes Software Corp..
    #property link http://www.metaquotes.net


    // ------------------------------------------------------------------
    //| Custom indior initialization serve |
    //p ------------------------------------------------------------------

    int init()

    return(0);

    //p ------------------------------------------------------------------
    //| Custom indior deinitialization function |
    // ------------------------------------------------------------------
    int deinit()

    //--

    //--
    return(0);

    // ------------------------------------------------------------------
    //| Custom indior iteration serve |
    // ------------------------------------------------------------------

    int start()


    dual Near = iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0);
    dual PriceNow = Bid;
    dual Trend = iMA(NULL,0,89,0,MODE_SMA,PRICE_CLOSE,0);
    double fast = iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,0);
    dual slow = iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,0);
    dual bullspread = (fast - slow);
    dual bearspread = (slow - fast);

    // Delete previous screen text
    ObjectDelete(script is currently operating );
    ObjectDelete(comment_label);
    ObjectDelete(reload);

    // Script running text
    ObjectCreate(script is running,OBJ_LABEL,0,0,0);
    ObjectSet(script is running,OBJPROP_XDISTANCE,0);
    ObjectSet(script is running,OBJPROP_YDISTANCE,15);
    ObjectSetText(script is running,TC SCRIPT ALERT ON,15,Arial,Yellow);

    // Requirements for BULL TC alert
    if ((PriceNow gt; Trend) (fast gt; slow) (PriceNow==Near) (bullspread gt; 0.0002))



    //Alerts
    SendMail(From - Statistics,BULL TC ALERT ON THE EUR-USD!!!) ;
    Alert(Symbol(), BULL,TC ALERT!) ;
    PlaySound(sirenhilo.wav);
    ObjectCreate(comment_label,OBJ_LABEL,0,0,0);
    ObjectSet(comment_label,OBJPROP_XDISTANCE,0);
    ObjectSet(comment_label,OBJPROP_YDISTANCE,35);
    ObjectSetText(comment_label,BULL TC ALERT! ,15,Arial,Lime);

    ObjectCreate(reload,OBJ_LABEL,0,0,0);
    ObjectSet(reload,OBJPROP_XDISTANCE,0);
    ObjectSet(reload,OBJPROP_YDISTANCE,55);
    ObjectSetText(reload,RELOAD SCRIPT,15,Arial,Blue);



    // If BEAR TC alert

    else if ((PriceNow lt; Trend) (fast lt; slow) (bearspread lt; 0.0002) (PriceNow == Near))


    SendMail(From - Statistics,BEAR TC ALERT ON THE EUR-USD!!!) ;
    Alert(Symbol(), BEAR,TC ALERT!) ;
    PlaySound(sirenhilo.wav);
    ObjectCreate(comment_label,OBJ_LABEL,0,0,0);
    ObjectSet(comment_label,OBJPROP_XDISTANCE,0);
    ObjectSet(comment_label,OBJPROP_YDISTANCE,35);
    ObjectSetText(comment_label,BEAR TC ALERT! ,15,Arial,Red);

    ObjectCreate(reload,OBJ_LABEL,0,0,0);
    ObjectSet(reload,OBJPROP_XDISTANCE,0);
    ObjectSet(reload,OBJPROP_YDISTANCE,55);
    ObjectSetText(reload,RELOAD SCRIPT,15,Arial,Blue);


    return(0);

  6. #6
    The difference is that script runs. Therefore you have to create a loop yourself. It should be something like that:

    int begin ()
    bool not_done=true;
    while(not_done)
    ....
    If(your illness here)
    SendMail();
    not_done = false;

    Seleep(1000);



    This may run the script until condition is fulfilled and exit it after sending the email. Hope this helps.

  7. #7
    Quote Originally Posted by ;
    Alert(Symbol(), BULL,TC ALERT!);
    PlaySound(sirenhilo.wav);
    Both will not work together unless you set a sleep period between each other (will not work in an indior though, only scripts and EAs).

    Alert();
    Sleep(500); // waiting for a half minute
    PlaySound();

  8. #8
    Thanks guys...I'll make those changes and see how it works out...

  9. #9
    Aktur:

    that I PM'd you about this but I am' -asking' here so others may benefit as well.

    I am having a little difficulty adding your loop in the correct place inside the code. Could you maybe re-paste my code here with your loop???

    Due

  10. #10
    Quote Originally Posted by ;
    :

    that I PM'd you about this but I'm're-asking' here so others might benefit as well.

    I am having a little trouble inserting your loop in the right place within the code. Can you possibly re-paste my code with your loop???

    Thank you
    Here it is (I haven't tested it)
    Inserted Code int begin () dual encompassing = iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0); double PriceNow = Bid; double Trend = iMA(NULL,0,89,0,MODE_SMA,PRICE_CLOSE,0); double fast = iMA(NULL,0,8,0,MODE_EMA,PRICE_CLOSE,0); double slow = iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE,0); double bullspread = (fast - slow); double bearspread = (slow - fast); // Delete previous screen text ObjectDelete(script is running); ObjectDelete(comment_label); ObjectDelete(reload); // Script running text ObjectCreate(script is operating,OBJ_LABEL,0,0,0); ObjectSet(script is operating,OBJPROP_XDISTANCE,0); ObjectSet(script is operating,OBJPROP_YDISTANCE,15); ObjectSetText(script is operating,TC SCRIPT ALERT ON,15,Arial,Yellow); #91;colour =red#93;bool not_done = true;#91;/colour #93; #91;colour =#ff0000#93;while(not_done)#91;/colour #93; // Conditions for BULL TC alert if ((PriceNow gt; Trend) (fast gt; slow) (PriceNow==Near) (bullspread gt; 0.0002)) //Alerts SendMail(From - Statistics,BULL TC ALERT ON THE EUR-USD!!!) ; #91;colour =red#93;not_done=false;#91;/ / colour #93; Alert(Symbol(), BULL,TC ALERT!) ; #91;colour =red#93;Sleep(500);#91;/colour #93; PlaySound(sirenhilo.wav); ObjectCreate(comment_label,OBJ_LABEL,0,0,0); ObjectSet(comment_label,OBJPROP_XDISTANCE,0); ObjectSet(comment_label,OBJPROP_YDISTANCE,35); ObjectSetText(comment_label,BULL TC ALERT! ,15,Arial,Lime); ObjectCreate(reload,OBJ_LABEL,0,0,0); ObjectSet(reload,OBJPROP_XDISTANCE,0); ObjectSet(reload,OBJPROP_YDISTANCE,55); ObjectSetText(reload,RELOAD SCRIPT,15,Arial,Blue); // If BEAR TC alert else if ((PriceNow lt; Trend) (fast lt; slow) (bearspread lt; 0.0002) (PriceNow == Near)) SendMail(From - Statistics,BEAR TC ALERT ON THE EUR-USD!!!) ; #91;colour =red#93;not_done=false;#91;/ / colour #93; Alert(Symbol(), BEAR,TC ALERT!) ; #91;colour =red#93;Sleep(500);#91;/colour #93; PlaySound(sirenhilo.wav); ObjectCreate(comment_label,OBJ_LABEL,0,0,0); ObjectSet(comment_label,OBJPROP_XDISTANCE,0); ObjectSet(comment_label,OBJPROP_YDISTANCE,35); ObjectSetText(comment_label,BEAR TC ALERT! ,15,Arial,Red); ObjectCreate(reload,OBJ_LABEL,0,0,0); ObjectSet(reload,OBJPROP_XDISTANCE,0); ObjectSet(reload,OBJPROP_YDISTANCE,55); ObjectSetText(reload,RELOAD SCRIPT,15,Arial,Blue); #91;colour =red93;Sleep(1000);#91;/colour #93; #91;color=red#93;#91;/colour #93; return(0);

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.