[Documentation error?] Indexing after binding

 

MQL4 Reference -> SetIndexBuffer:

Note

After binding, the dynamic array buffer[] will be indexed as in common arrays, even if the indexing of timeseries is pre-installed for the bound array. If you want to change the order of access to elements of the indicator array, use the ArraySetAsSeries() function after binding the array using the SetIndexBuffer() function.

Seems like it's not true. Or am I misunderstanding something?

#property strict
#property indicator_chart_window
#property indicator_buffers 1

double buffer[];

int OnInit()
  {
   Alert("Before binding: as_series ", ArrayGetAsSeries(buffer)); // Before binding: as_series false
   SetIndexBuffer(0,buffer);
   Alert("After binding: as_series ", ArrayGetAsSeries(buffer));  // After binding: as_series true
   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[])
  {
   if(prev_calculated == 0)
      Alert("OnCalculate: as_series ", ArrayGetAsSeries(buffer)); // OnCalculate: as_series true
   return(rates_total);
  }


SetIndexBuffer - Custom Indicators - MQL4 Reference
SetIndexBuffer - Custom Indicators - MQL4 Reference
  • docs.mql4.com
SetIndexBuffer - Custom Indicators - MQL4 Reference
 
Looks like a mistaken copy of the MQL5 documentation
 
Vladislav Boyko:

MQL4 Reference -> SetIndexBuffer:

Note

After binding, the dynamic array buffer[] will be indexed as in common arrays, even if the indexing of timeseries is pre-installed for the bound array. If you want to change the order of access to elements of the indicator array, use the ArraySetAsSeries() function after binding the array using the SetIndexBuffer() function.

Seems like it's not true. Or am I misunderstanding something?


Yes you misunderstood.

It says you need to do it like this :

int OnInit()
  {
   SetIndexBuffer(0,buffer);
   ArraySetAsSeries(buffer,true);
   return(INIT_SUCCEEDED);
  }

And not like this :

int OnInit()
  {
   ArraySetAsSeries(buffer,true);  Wrong way 
   SetIndexBuffer(0,buffer);
   return(INIT_SUCCEEDED);
  }
 
Alain Verleyen #:

Yes you misunderstood.

It says you need to do it like this :

And not like this :

It's clear. I'm talking about the first part of the quote:

"After binding, the dynamic array buffer[] will be indexed as in common arrays, even if the indexing of timeseries is pre-installed for the bound array"

"the array will be indexed as in common arrays" - this means that ArrayGetAsSeries() must return false, am I understanding it correctly?

double buffer[];

int OnInit()
  {
   SetIndexBuffer(0,buffer);
   Alert(isIndexedAsInCommonArrays(buffer) ? "Documentation is ok" : "Documentation error");
   return(INIT_SUCCEEDED);
  }

bool isIndexedAsInCommonArrays(const double &arr[])
  {
   return(!ArrayGetAsSeries(arr));
  }
 
Vladislav Boyko #:

It's clear. I'm talking about the first part of the quote:

"After binding, the dynamic array buffer[] will be indexed as in common arrays, even if the indexing of timeseries is pre-installed for the bound array"

"the array will be indexed as in common arrays" - this means that ArrayGetAsSeries() must return false, am I understanding it correctly?

isIndexedAsInCommonArrays() testing:

void OnStart()
  {
   double commonArray[];
   string isOrIsNot = isIndexedAsInCommonArrays(commonArray) ? "is" : "is not";
   Alert("Common array ", isOrIsNot, " indexed like in common array");
  }

bool isIndexedAsInCommonArrays(const double &arr[])
  {
   return(!ArrayGetAsSeries(arr));
  }
 
Vladislav Boyko #:

It's clear. I'm talking about the first part of the quote:

"After binding, the dynamic array buffer[] will be indexed as in common arrays, even if the indexing of timeseries is pre-installed for the bound array"

"the array will be indexed as in common arrays" - this means that ArrayGetAsSeries() must return false, am I understanding it correctly?

Yes the documentation is wrong for MQL4. It was copied from MQL5 which works differently.
Reason: