MT4 New Bar in indicator

Back to topics list To post a new topic, please log in or register
avatar
3
imamushroom 2015.08.05 22: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. 

avatar
Moderator
3427
GumRai 2015.08.05 23: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.
avatar
872
eevviill 2015.08.06 13: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;

Back to topics list  

To add comments, please log in or register