Result of WindowBarsPerChart() for a given chart changes when I navigate to another window

 

I am trying to use the result of

WindowsBarsPerChart()

in an MQL4 indicator attached to a chart. By using Print() I can view the result in the 'Experts' tab of the terminal window.

As I navigate between other symbols' chart windows I see that the value varies despite the indicator being attached only in the original window/chart.

I see the same behaviour if I expose the values of

WindowFirstVisibleBar()

and

ChartGetInteger(ChartID(),CHART_VISIBLE_BARS)

I created a trivial indicator to attach to a chart to demonstrate the issue.

#property strict
#property indicator_chart_window 
#property indicator_buffers 1 
#property indicator_label1  "Line" 
#property indicator_type1   DRAW_LINE 
#property indicator_color1  clrDarkBlue 
#property indicator_style1  STYLE_SOLID 
#property indicator_width1  1 

double         LineBuffer[];


int OnInit() 
  { 
   SetIndexBuffer(0,LineBuffer,INDICATOR_DATA); 
   

   return(INIT_SUCCEEDED); 
  } 
 
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[]) 
  { 

Print(WindowBarsPerChart());

   return(rates_total); 
   
  }

Is this expected behaviour? Especially in the case of the use of CHART_VISIBLE_BARS where the ChartID() has been explicitly defined.

Thanks,

James

 
jamesh992000: in an MQL4 indicator attached to a chart .… the value varies despite the indicator being attached only in the original window/chart.

You have “an indicator attached to a chart.” You changed the chart, your indicator is now on the changed chart. There is no “original chart.”

 
William Roeder #:

You have “an indicator attached to a chart.” You changed the chart, your indicator is now on the changed chart. There is no “original chart.”

And yet if my trivial indicator were to have

Print(Bid);

rather than

Print(WindowBarsPerChart());

then even by flicking between the charts of various symbols I would always see the price of the original chart.