Price Alert

Discussion in 'MetaTrader Indicators' started by Enivid, Apr 27, 2009.

  1. Hi @Enivid Could you please elaborate more on this?. I could not understand.
    How to add that in this code
    Code (MQL4):
    #property copyright ""
    #property link      ""

    #property indicator_chart_window

    extern double SoundWhenPriceGoesAbove = 0;
    extern double SoundWhenPriceGoesBelow = 0;

    int init()
    {
       if (SoundWhenPriceGoesAbove > 0)
       {
          ObjectCreate("SoundWhenPriceGoesAbove", OBJ_HLINE, 0, Time[0], SoundWhenPriceGoesAbove);
          ObjectSet("SoundWhenPriceGoesAbove", OBJPROP_STYLE, STYLE_SOLID);
          ObjectSet("SoundWhenPriceGoesAbove", OBJPROP_COLOR, Magenta);
          ObjectSet("SoundWhenPriceGoesAbove", OBJPROP_WIDTH, 1);
       }
       if (SoundWhenPriceGoesBelow > 0)
       {
          ObjectCreate("SoundWhenPriceGoesBelow", OBJ_HLINE, 0, Time[0], SoundWhenPriceGoesBelow);
          ObjectSet("SoundWhenPriceGoesBelow", OBJPROP_STYLE, STYLE_SOLID);
          ObjectSet("SoundWhenPriceGoesBelow", OBJPROP_COLOR, Magenta);
          ObjectSet("SoundWhenPriceGoesBelow", OBJPROP_WIDTH, 1);
       }
       return(0);
    }


    int deinit()
    {
       ObjectDelete("SoundWhenPriceGoesAbove");
       ObjectDelete("SoundWhenPriceGoesBelow");
       return(0);
    }

    int start()
    {

       if (ObjectGet("SoundWhenPriceGoesAbove", 1) != SoundWhenPriceGoesAbove)
         SoundWhenPriceGoesAbove = ObjectGet("SoundWhenPriceGoesAbove", 1);
       if (ObjectGet("SoundWhenPriceGoesBelow", 1) != SoundWhenPriceGoesBelow)
         SoundWhenPriceGoesBelow = ObjectGet("SoundWhenPriceGoesBelow", 1);


       if ((Bid > SoundWhenPriceGoesAbove) && (SoundWhenPriceGoesAbove > 0))
       {
          PlaySound("alert.wav");
       }
       if ((Bid < SoundWhenPriceGoesBelow) && (SoundWhenPriceGoesBelow > 0))
       {
          PlaySound("alert.wav");
       }
       return(0);
    }

     
     
  2. Enivid

    Enivid Administrator Staff Member

    7,761
    253
    114
  3. Oops!! I'm really 0 in coding. I can just modify code bit only. could not understand that. If it's easy could you plz code for me?.
     
  4. Joeyshen

    Joeyshen Newbie

    2
    0
    1
    Hi Enivid,

    When the market price hits the alert line, it will be removed. But would it be possible for the alert line to remain for multiple alert activation?
    Thank you!!
     
  5. Enivid

    Enivid Administrator Staff Member

    7,761
    253
    114
    Yes, you can remove or comment out the lines 75-76, 83-84, and 91-92 if we are talking about MT4 version. However, I am not sure you will like being flooded by lots of alerts.
     
  6. Joeyshen

    Joeyshen Newbie

    2
    0
    1
    Thank you!, but my apologies that I forgotten to state that i'm using MT5. May i know how was it done in MT5 too? Thank you!
    oh and why i'm doing so its because since im trading more on 1 and 5min timeframe, so i could just shift the alert to the price for my next's trade rather than keep on inserting new indicator and keying in the input value.
     
  7. Enivid

    Enivid Administrator Staff Member

    7,761
    253
    114
    Same thing with lines 88-89, 96-97, and 104-105.
     
  8. Neville

    Neville Newbie

    3
    0
    1
    Hi Enivid, I am new to this. Thank you much for your service. I have tried to modify the Price Alert Indicator to Send Notification to my iphone, but I get errors when changing SendMail to SendNotification and try to compile. Would you, or someone, please provide an example of how this should be done?

    Thank you very much, Neville.
     
  9. Enivid

    Enivid Administrator Staff Member

    7,761
    253
    114
  10. Neville

    Neville Newbie

    3
    0
    1
    Yes, thank you. That is what I did, but I am getting an error (3 times, one for each occurrence of SendNotification).

    Here is what I did (3 times) and the error (3 times):

    Code (MQL4):

    if ((Ask > SoundWhenPriceGoesAbove) && (SoundWhenPriceGoesAbove > 0))
       {
          Alert("Price above the alert level.");
          PlaySound("alert.wav");
          SendNotification ("Price for " + Symbol() +  " above the alert level " + Ask, "Price for " + Symbol() +  " reached " + Ask + " level, which is above your alert level of " + SoundWhenPriceGoesAbove);
          ObjectDelete("SoundWhenPriceGoesAbove");
          SoundWhenPriceGoesAbove = 0;
       }
    Error I receive:

    'SendNotification' - wrong parameters count PriceAlert.mq4 74 7
     
    Last edited by a moderator: Sep 19, 2017
  11. Enivid

    Enivid Administrator Staff Member

    7,761
    253
    114
    Please do not forget to use code highlighting - it makes things much more readable.

    As the error states, you are trying to call SendNotification() with a wrong number parameters. As you can see in my example, it takes only one parameter. Your call contains two parameters - the comma delimits them. When you use SendMail(), it takes two parameters - the subject of the email and the body of the message. When you use SendNotification() it can only take the message - there are no subjects in push notifications.
     
  12. Neville

    Neville Newbie

    3
    0
    1
    Thanks again! I removed the first area, before the comma, and it is good now.

    Code (MQL4):
     SendNotification("Price for " + Symbol() +  " reached " + Bid + " level, which is below your alert level of " + SoundWhenPriceGoesBelow);
     
    Last edited by a moderator: Sep 20, 2017
  13. muscae

    muscae Trader

    5
    2
    9
    I am using one indicator for more than 2 years that cost me $10 but does anything that I need for my trades.
    All I need is to be warned before price touches some level.
    So this indicator as a field of Distance so we can choose how many pips before will be the warning. That warning could be pop up, email or push. It works with any draw line including trendlines, but u can exclude by the name or thickness. Also has a feature of changing the color of the line.
    I am not here trying to spam the forum, just posting as way of inspiration for the features that I think this kind of indicator must have.
    Here is the link https://www.mql5.com/en/market/product/6086
     

Share This Page