Download MetaTrader 5
To add comments, please log in or register
Deposit to your account via Visa QIWI Wallet
chua le
234
chua le 2015.06.25 08:26 
//+------------------------------------------------------------------+
//|                                              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]; 

chua le
234
chua le 2015.06.26 14:55  
Kindly help, I have been stcucked for one month plus.
whroeder1
13590
whroeder1 2015.06.26 18:05  
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.
Keith Watford
Moderator
7862
Keith Watford 2015.06.26 21:11  
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.
/
To add comments, please log in or register