Alert Issue - Anyone Care To Take A Quick Look?

 

Hi everyone,


I've trying to code a simple indicator which Alerts when price reaches Yesterday's High and Low. The Alert works fine but the only problem is that I want it to stop alerting once it has alerted already. My indicator keep alerting until I manually remove it.

In the code I've created a "test" section, which is currently commented. This section can be used to create a temporary alert price to test the indicator, so we don't have to wait for the price to reach Yesterday High/Low.


I would appreciate your comments and suggestions

#property indicator_chart_window
   
double Day_Price[][6];
double SoundWhenPriceIsYesterdayHigh = 0;
double SoundWhenPriceIsYesterdayLow = 0;

double test = 0;
    
int init()
  {
return(0);
}
  
//-------------------------------------------------------- 
  
int deinit()
  {
 
ObjectDelete("SoundWhenPriceIsYesterdayHigh");  
ObjectDelete("SoundWhenPriceIsYesterdayLow");  

/*
ObjectDelete("test");
*/

return(0);
}
//--------------------------------------------------------- 

int start()
{

  ArrayCopyRates(Day_Price,(Symbol()), 1440);


   SoundWhenPriceIsYesterdayHigh = Day_Price[1][3];
   SoundWhenPriceIsYesterdayLow = Day_Price[1][2];
   
   
 if (SoundWhenPriceIsYesterdayHigh > 0)
   {
      ObjectCreate("SoundWhenPriceIsYesterdayHigh", OBJ_HLINE, 0, Time[0], SoundWhenPriceIsYesterdayHigh);
      ObjectSet("SoundWhenPriceIsYesterdayHigh", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("SoundWhenPriceIsYesterdayHigh", OBJPROP_COLOR, Green);
      ObjectSet("SoundWhenPriceIsYesterdayHigh", OBJPROP_WIDTH, 1);
   } 
   
  
 if (SoundWhenPriceIsYesterdayLow > 0)
   {
      ObjectCreate("SoundWhenPriceIsYesterdayLow", OBJ_HLINE, 0, Time[0], SoundWhenPriceIsYesterdayLow);
      ObjectSet("SoundWhenPriceIsYesterdayLow", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("SoundWhenPriceIsYesterdayLow", OBJPROP_COLOR, Red);
      ObjectSet("SoundWhenPriceIsYesterdayLow", OBJPROP_WIDTH, 1);
   } 
   
   
 if ((Bid == SoundWhenPriceIsYesterdayLow) || (Ask == SoundWhenPriceIsYesterdayLow))
   {
      Alert("SoundWhenPriceIsYesterdayLow");
      PlaySound("alert.wav");
      ObjectDelete("SoundWhenPriceIsYesterdayLow");
      SoundWhenPriceIsYesterdayLow = 0;
   }  
      
 if ((Bid == SoundWhenPriceIsYesterdayHigh) || (Ask == SoundWhenPriceIsYesterdayHigh))
   {
      Alert("SoundWhenPriceIsYesterdayHigh");
      PlaySound("alert.wav");
      ObjectDelete("SoundWhenPriceIsYesterdayHigh");
      SoundWhenPriceIsYesterdayHigh = 0;
   }  
  
  /*
    test = SoundWhenPriceIsYesterdayHigh-Point*53;
    
 if ((Bid == test) || (Ask == test))
   {
      Alert("test");
      PlaySound("alert.wav");
      ObjectDelete("test");
      test = 0;
   }  
   
   if (test > 0)
   {
      ObjectCreate("test", OBJ_HLINE, 0, Time[0], test);
      ObjectSet("test", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("test", OBJPROP_COLOR, Yellow);
      ObjectSet("test", OBJPROP_WIDTH, 1);
   } 
*/

ObjectsRedraw();

   return(0);
}
 
the_one wrote >>

You could use a ctr(counter) to have the no of alerts/alarms and that function should exit after the no of alerts set.

Something like, If Alert_Cntr <5, keep alerting and exit if it is = 5.

And within that loop increment the Alert_Cntr. And depending on the timeframe you use, you can reset the counter to 0 again if that is required so that, any new fresh alerts should not be missed.

Goodluck.

 
Kent:

You could use a ctr(counter) to have the no of alerts/alarms and that function should exit after the no of alerts set.

Something like, If Alert_Cntr <5, keep alerting and exit if it is = 5.

And within that loop increment the Alert_Cntr. And depending on the timeframe you use, you can reset the counter to 0 again if that is required so that, any new fresh alerts should not be missed.

Goodluck.

Hi Kent,


Thanks for the quick response. It is a good idea. I'll try to implement it.


One quick question though. How can I reset the counter to 0 for Daily charts? What and where I need for that? Any suggestions.



Thanks again

Reason: