Download MetaTrader 5

MT4 New Bar in indicator

To add comments, please log in or register
imamushroom
215
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. 

Keith Watford
Moderator
10611
Keith Watford  
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
19307
Vasyl Nosal  
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