HELP with code for my Candle Close price Indicator !! PLEASE

 

I've put the following together to try and alert me when a candle on a certain timeframe close above my Object Line it sends alert etc...However at the moment it just spams me with alerts when price is above or below my line. So the alerting bit is fine but it doesnt seem to be taking the timeframe into account and the candle close price.


Can some one please help...

1. Make it only send 1 or 2 alerts not continuous

2. Have it take the timeframe and candle close before sending the alert.


What i'm trying to achieve is : When a future 1hr candle closes above/below the price line send alert.


//+------------------------------------------------------------------+
//|                                                 Candle Close.mq4 |
//|                        Copyright 2019, MetaQuotes Software Corp. | 
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp." 
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict 
#property indicator_chart_window
extern int Timeframe = PERIOD_H1; //Set TimeFrame of candle close above 60=1hr          
extern string LineName="MyLine1";
extern color LineColor=AliceBlue; 
extern int LineStyle=STYLE_SOLID;
extern int AlertPipRange=5; 
extern string AlertWav="alert.wav";
extern bool SoundAlert = true;
extern bool PopupAlert = true;
extern bool PushNotificationAlert = true; 
extern bool EmailAlert = false;
            
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator
//---
   return(0); 
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       | 
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete(LineName); 
//----
  return(0); 
  }
 //+------------------------------------------------------------------+
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+
int start()
   {
    int  counted_bars=IndicatorCounted(); 
    
      ObjectCreate(LineName, OBJ_HLINE, 0, 0, Bid);
      ObjectSet(LineName, OBJPROP_STYLE, LineStyle); 
      ObjectSet(LineName, OBJPROP_COLOR, LineColor);
      ObjectSet(LineName, OBJPROP_WIDTH,3); 
      
      double val = ObjectGet( LineName, OBJPROP_PRICE1);       
      double testclose = iClose(NULL,Timeframe,0);

   if (testclose > val)
     {
       if (SoundAlert)  PlaySound(AlertWav); 
       if (PopupAlert)  Alert("Price Closed Above Resistance on "+Symbol());
       if (PushNotificationAlert) SendNotification("TRADE ALERT Closed Above "+LineName+" on "+Symbol()); 
       if (EmailAlert) SendMail("HLine Alert on "+Symbol(),"price hit "+LineName+" on "+Symbol());
     }
    
   
   if (testclose <= val)
     {
      if (SoundAlert)  PlaySound(AlertWav); 
      if (PopupAlert)  Alert("Price Closed Below Support on "+Symbol());
      if (PushNotificationAlert) SendNotification("TRADE ALERT Closed Below "+LineName+" on "+Symbol()); 
      if (EmailAlert) SendMail("HLine Alert on "+Symbol(),"price hit "+LineName+" on "+Symbol()); 
     
     
     } 
    
    return(0);
   } 

//+------------------------------------------------------------------+
 
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. Initializing problem while compiling the...
 
Post your request as a job in Freelance section.