price allert

 

Hi guys, this allert sounds when the price exceeds or is on an exact price level set by the user when the user is charging, but sometimes it works and sometimes no, is there someone that can help me fix it ?

extern double SuonoQuandoPrezzoSupera = 0;
extern string Commento_Up;
extern double SuonoQuandoPrezzoScendeSotto = 0;
extern string Commento_down;
extern double SuonoAlPrezzoEsatto = 0;
extern string Commento;
extern bool SendEmail = false; //If true e-mail is sent to the e-mail address set in your MT4. E-mail SMTP Server settings should also be configured in your MT4


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() 
{
   if (SuonoAlPrezzoEsatto > 0)
   {
      ObjectCreate("SuonoAlPrezzoEsatto", OBJ_HLINE, 0, Time[0], SuonoAlPrezzoEsatto);
      ObjectSet("SuonoAlPrezzoEsatto", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("SuonoAlPrezzoEsatto", OBJPROP_COLOR, Yellow);
      ObjectSet("SuonoAlPrezzoEsatto", OBJPROP_WIDTH, 1);
      ObjectSetText("SuonoQuandoPrezzoSupera","Commento: " +Commento, 12,NULL,clrYellow);
   }
   if (SuonoQuandoPrezzoSupera > 0)
   {
      ObjectCreate("SuonoQuandoPrezzoSupera", OBJ_HLINE, 0, Time[0], SuonoQuandoPrezzoSupera);
      ObjectSet("SuonoQuandoPrezzoSupera", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("SuonoQuandoPrezzoSupera", OBJPROP_COLOR, Green);
      ObjectSet("SuonoQuandoPrezzoSupera", OBJPROP_WIDTH, 1);
      ObjectSetText("SuonoQuandoPrezzoSupera","Commento_up: " +Commento_Up, 12,NULL,clrGreen);
   }
   if (SuonoQuandoPrezzoScendeSotto > 0)
   {
      ObjectCreate("SuonoQuandoPrezzoScendeSotto", OBJ_HLINE, 0, Time[0], SuonoQuandoPrezzoScendeSotto);
      ObjectSet("SuonoQuandoPrezzoScendeSotto", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("SuonoQuandoPrezzoScendeSotto", OBJPROP_COLOR, Red);
      ObjectSet("SuonoQuandoPrezzoScendeSotto", OBJPROP_WIDTH, 1);
      ObjectSetText("SuonoQuandoPrezzoScendeSotto","Commento_down: " +Commento_down, 12,NULL,clrBlack);
   }
   return(0);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//*+------------------------------------------------------------------+
/*int deinit()
{
   ObjectDelete("SuonoAlPrezzoEsatto");
   ObjectDelete("SuonoQuandoPrezzoSupera");
   ObjectDelete("SuonoQuandoPrezzoScendeSotto");
   return(0);
}*/
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
 // added by Mn -----------------------------------------------------------
   if (ObjectGet("SuonoQuandoPrezzoSupera", 1) != SuonoQuandoPrezzoSupera)
     SuonoQuandoPrezzoSupera = ObjectGet("SuonoQuandoPrezzoSupera", 1);
   if (ObjectGet("SuonoQuandoPrezzoScendeSotto", 1) != SuonoQuandoPrezzoScendeSotto)
     SuonoQuandoPrezzoScendeSotto = ObjectGet("SuonoQuandoPrezzoScendeSotto", 1);
   if (ObjectGet("SuonoAlPrezzoEsatto", 1) != SuonoAlPrezzoEsatto)
     SuonoAlPrezzoEsatto = ObjectGet("SuonoAlPrezzoEsatto", 1);
 // added by Mn -----------------------------------------------------------

   if ((Ask > SuonoQuandoPrezzoSupera) && (SuonoQuandoPrezzoSupera > 0))
   {
      Alert("Prezzo di " + Symbol() +  " ha superato "+ Ask + "Commento: " + Commento_Up);
      PlaySound("alert.wav");
      //SendMail("Prezzo di " + Symbol() +  " ha superato " + Ask, "Price for " + Symbol() +  " reached " + Ask + " level, which is above your alert level of " + SuonoQuandoPrezzoSupera);
      //ObjectDelete("SuonoQuandoPrezzoSupera");
      SuonoQuandoPrezzoSupera = 0;
   }
   if ((Bid < SuonoQuandoPrezzoScendeSotto) && (SuonoQuandoPrezzoScendeSotto > 0))
   {
      Alert("Prezzo di " + Symbol() +  " è sceso sotto "+ Bid + "\nCommento: " + Commento_down);
      PlaySound("alert.wav");
      SendMail("Price for " + Symbol() +  " below the alert level " + Bid, "Price for " + Symbol() +  " reached " + Bid + " level, which is below your alert level of " + SuonoQuandoPrezzoScendeSotto);
      //ObjectDelete("SuonoQuandoPrezzoScendeSotto");
      SuonoQuandoPrezzoScendeSotto = 0;
   }
   if ((Bid == SuonoAlPrezzoEsatto) || (Ask == SuonoAlPrezzoEsatto))
   {
      Alert("Prezzo di " + Symbol() +  " é "+ Ask + "Commento: " + Commento);
      PlaySound("alert.wav");
      SendMail("Price for " + Symbol() +  " exactly at the alert level " + Ask, "Price for " + Symbol() +  " reached " + Ask + "/" + Bid + " level, which is exactly your alert level of " + SuonoAlPrezzoEsatto);
      //ObjectDelete("SuonoAlPrezzoEsatto");
      SuonoAlPrezzoEsatto = 0;
   }
   return(0);
}
//+------------------------------------------------
 
texcs81: this allert sounds when the price exceeds or is on an exact price level set by the user when the user is charging, but sometimes it works and sometimes no,
  1. Why did you post your MT4 question in the Root / MT5 Indicators section instead of the MQL4 section (bottom of the Root page?) General rules and best pratices of the Forum. - General - MQL5 programming forum
  2. SuonoQuandoPrezzoSupera = ObjectGet("SuonoQuandoPrezzoSupera", 1);
    Don't hard code numbers. Use the appropriate symbols OBJPROP_PRICE1
  3. if ((Ask > SuonoQuandoPrezzoSupera) && (SuonoQuandoPrezzoSupera > 0))
    :
    if ((Bid < SuonoQuandoPrezzoScendeSotto) && (SuonoQuandoPrezzoScendeSotto > 0))
    :
    if ((Bid == SuonoAlPrezzoEsatto) || (Ask == SuonoAlPrezzoEsatto))
    Doubles are rarely equal. The == operand. - MQL4 forum
 
I modified the code as follows
extern double SuonoQuandoPrezzoSupera = 0;
extern string Commento_Up;
extern double SuonoQuandoPrezzoScendeSotto = 0;
extern string Commento_down;
//extern double SuonoAlPrezzoEsatto = 0;
//extern string Commento;
extern bool SendEmail = false; //If true e-mail is sent to the e-mail address set in your MT4. E-mail SMTP Server settings should also be configured in your MT4
bool suonoUp =true, suonoDw =true;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() 
{
   DisegnaLineaUp(SuonoQuandoPrezzoSupera);
   DisegnaLineaDw(SuonoQuandoPrezzoScendeSotto);
   return(0);
}
void DisegnaLineaDw (double DisegnaLineaDw){

      DisegnaLineaDw = SuonoQuandoPrezzoScendeSotto;
      ObjectCreate("SuonoQuandoPrezzoScendeSotto", OBJ_HLINE, 0, Time[0], SuonoQuandoPrezzoScendeSotto);
      ObjectSet("SuonoQuandoPrezzoScendeSotto", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("SuonoQuandoPrezzoScendeSotto", OBJPROP_COLOR, Red);
      ObjectSet("SuonoQuandoPrezzoScendeSotto", OBJPROP_WIDTH, 1);
      ObjectSetText("SuonoQuandoPrezzoScendeSotto","Commento_down: " +Commento_down, 12,NULL,clrBlack);
     
      ObjectCreate("DisegnaLineaRed", OBJ_HLINE, 0, Time[0], DisegnaLineaDw); 
      ObjectSet("DisegnaLineaRed", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("DisegnaLineaRed", OBJPROP_COLOR, Red);
      ObjectSet("DisegnaLineaRed", OBJPROP_WIDTH, 1);
      ObjectSetText("DisegnaLineaRed","Commento_up: " +Commento_Up, 12,NULL,clrGreen);
  }
  
void DisegnaLineaUp(double DisegnaLineaUp){
  
      DisegnaLineaUp = SuonoQuandoPrezzoSupera;
   
      ObjectCreate("SuonoQuandoPrezzoSupera", OBJ_HLINE, 0, Time[0], SuonoQuandoPrezzoSupera);
      ObjectSet("SuonoQuandoPrezzoSupera", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("SuonoQuandoPrezzoSupera", OBJPROP_COLOR, Green);
      ObjectSet("SuonoQuandoPrezzoSupera", OBJPROP_WIDTH, 1);
      ObjectSetText("SuonoQuandoPrezzoSupera","Commento_up: " +Commento_Up, 12,NULL,clrGreen);
      
      ObjectCreate("DisegnaLineaGreen", OBJ_HLINE, 0, Time[0], DisegnaLineaUp); 
      ObjectSet("DisegnaLineaGreen", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("DisegnaLineaGreen", OBJPROP_COLOR, Green);
      ObjectSet("DisegnaLineaGreen", OBJPROP_WIDTH, 1);
      ObjectSetText("DisegnaLineaGreen","Commento_up: " +Commento_Up, 12,NULL,clrGreen);
}

int start()
{
 // added by Mn -----------------------------------------------------------
   if (ObjectGet("SuonoQuandoPrezzoSupera", 1) != SuonoQuandoPrezzoSupera){
     SuonoQuandoPrezzoSupera = ObjectGet("SuonoQuandoPrezzoSupera", 1);
     SuonoQuandoPrezzoSupera =ObjectGet("DisegnaLineaGreen", 1);
     SuonoQuandoPrezzoScendeSotto = ObjectGet("DisegnaLineaRed", 1);
     }
   if (ObjectGet("SuonoQuandoPrezzoScendeSotto", 1) != SuonoQuandoPrezzoScendeSotto){
     SuonoQuandoPrezzoScendeSotto = ObjectGet("SuonoQuandoPrezzoScendeSotto", 1);
     
    
     }
 // added by Mn -----------------------------------------------------------

   if ((Ask > SuonoQuandoPrezzoSupera) && (SuonoQuandoPrezzoSupera > 0)&& suonoUp== true )
   {
      Alert("Prezzo di " + Symbol() +  " ha superato "+ Ask + "Commento: " + Commento_Up);
      PlaySound("alert.wav");
      suonoUp=false;
    //SendMail("Prezzo di " + Symbol() +  " ha superato " + Ask, "Price for " + Symbol() +  " reached " + Ask + " level, which is above your alert level of " + SuonoQuandoPrezzoSupera);
    //ObjectDelete("SuonoQuandoPrezzoSupera");
      SuonoQuandoPrezzoSupera = 0;
    
   }
   if ((Bid < SuonoQuandoPrezzoScendeSotto) && (SuonoQuandoPrezzoScendeSotto > 0)&& suonoDw== true )
   {
      Alert("Prezzo di " + Symbol() +  " è sceso sotto "+ Bid + "\nCommento: " + Commento_down);
      PlaySound("alert.wav");
      suonoDw=false;
  //  SendMail("Price for " + Symbol() +  " below the alert level " + Bid, "Price for " + Symbol() +  " reached " + Bid + " level, which is below your alert level of " + SuonoQuandoPrezzoScendeSotto);
  //  ObjectDelete("SuonoQuandoPrezzoScendeSotto");
      SuonoQuandoPrezzoScendeSotto = 0;
   }
   return(0);
}
//+-------------

 the "DisegnaLineaUp" function draws a "green" line on the level you set to the "SuonoQuandoPrezzoSupera" variable when you load the indicator, the "DisegnaLineaDw" function should draw a "red" line on the layer you set to the variable "SuonoQuandoPrezzoScendeSotto" but it does not work and I do not understand why, could you please help me?

 
texcs81: but it does not work and I do not understand why,
      DisegnaLineaDw = SuonoQuandoPrezzoScendeSotto;
      ObjectCreate("SuonoQuandoPrezzoScendeSotto", OBJ_HLINE, 0, Time[0], SuonoQuandoPrezzoScendeSotto);
      ObjectCreate("DisegnaLineaRed",              OBJ_HLINE, 0, Time[0], DisegnaLineaDw); 
How do you expect to see two lines when you draw them on top of each other?
 

Thank you, I resolved,

Now, I would like to know, once I load the indicator if I do double click on a line, you do not select only the line but, should appear also the parameters input window "the one that appears the first time you enter the indicator";

another question, if it is possible, that when you move a line (graphically with the mouse) it assigns the new values to the variables "SuonoQuandoPrezzoSupera", "SuonoQuandoPrezzoScendeSotto;"  in order to reset the indicator graphically.

Reason: