Single Alert within One Bar

 
//+------------------------------------------------------------------+
//|                                              M5 Bar Alert.mq4  |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.abc.com"
#property version   "1.00"
#property strict
double     BarM5;
int        xMultiply;
datetime   PreviousTime;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {

//---
if(Digits==3) xMultiply=100;
if(Digits==5) xMultiply=10000;
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---

   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {
  //if(Time[0]==PreviousTime)  return(0);         //EA will not go past this point unless it is a new bar
  //PreviousTime=Time[0];
   
   BarM5=(iClose(Symbol(),PERIOD_M5,0)-iOpen(Symbol(),PERIOD_M5,0))*xMultiply;
  
    
   Comment ("BarM5 ="+DoubleToString(BarM5,Digits)+"\n"
           );
         
     
       if(BarM5>3  )SendNotification ("BarM5 >3 "+Symbol());
     
       if(BarM5<-3 )SendNotification ("BarM5 <-3 "+Symbol());
      
          return(0); 
  }
//+------------------------------------------------------------------+

Hi,

I have the coding above to alert me when M5>3 or <-3, the problem is i received many alerts  within a single bar. So where shall I insert  the following  coding  to receive only  one alert for a bar if condtioton met? 

if(Time[0]==PreviousTime)  return(0);         //EA will not go past this point unless it is a new bar

  PreviousTime=Time[0]; 

 
Kindly help, I have been stcucked for one month plus.
 
learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
 
chuale:

Hi,

I have the coding above to alert me when M5>3 or <-3, the problem is i received many alerts  within a single bar. So where shall I insert  the following  coding  to receive only  one alert for a bar if condtioton met? 

if(Time[0]==PreviousTime)  return(0);         //EA will not go past this point unless it is a new bar

  PreviousTime=Time[0]; 

 

If you want the Comment to update every tick, then insert it after the Comment code and before the alert code.
Reason: