Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 has event handling?
imamushroom
134
imamushroom 2015.08.05 20:44 

Hi,

Could someone please show me how I can detect and only execute something at the open of a new bar please?

I know how to do it in an EA but struggling with an indicator (it's the first indicator I've written!)

Thanks in advance. 

Keith Watford
Moderator
7875
Keith Watford 2015.08.05 21:08  
imamushroom:

Hi,

Could someone please show me how I can detect and only execute something at the open of a new bar please?

I know how to do it in an EA but struggling with an indicator (it's the first indicator I've written!)

Thanks in advance. 

If you know how to do it in an EA, then just do the same in an indicator.
Vasyl Nosal
18199
Vasyl Nosal 2015.08.06 11:34  
imamushroom:

Hi,

Could someone please show me how I can detect and only execute something at the open of a new bar please?

I know how to do it in an EA but struggling with an indicator (it's the first indicator I've written!)

Thanks in advance. 

int prevbars;

//////////////////////////////////////////////////////////////////
int OnCalculate(const int rates_total,const int prev_calculated,const datetime &time[],const double &open[],const double &high[],
                const double &low[],const double &close[],const long &tick_volume[],const long &volume[],const int &spread[])
  {
  //new bar
if(Bars==prevbars) return(rates_total);
prevbars=Bars;
/
To add comments, please log in or register