MQL4 Reference Array Functions ArrayGetAsSeries


It checks direction of an array index.

bool  ArrayGetAsSeries(
   const void&  array[]    // array for checking



[in]  Checked array.

Return Value

Returns true, if the specified array has the AS_SERIES flag set, i.e. access to the array is performed back to front as in timeseries. A timeseries differs from a usual array in that the indexing of timeseries elements is performed from its end to beginning (from the newest data to old).


To check whether an array belongs to timeseries, use the ArrayIsSeries() function. Arrays of price data passed as input parameters into the OnCalculate() function do not obligatorily have the indexing direction the same as in timeseries. The necessary indexing direction can be set using the ArraySetAsSeries() function.


#property description "Indicator calculates absolute values of the difference between"
#property description "Open and Close or High and Low prices displaying them in a separate subwindow"
#property description "as a histrogram."
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
//--- input parameters
input bool InpAsSeries=true// Indexing direction in the indicator buffer
input bool InpPrices=true;   // Calculation prices (true - Open,Close; false - High,Low)
//--- indicator buffer
double ExtBuffer[];
//| Calculating indicator values                                     |
void CandleSizeOnBuffer(const int rates_total,const int prev_calculated,
                        const double &first[],const double &second[],double &buffer[])
//--- start variable for calculation of bars
   int start_index=prev_calculated;
//--- work at the last bar if the indicator values have already been calculated at the previous tick
//--- define indexing direction in arrays
   bool as_series_first=ArrayGetAsSeries(first);
   bool as_series_second=ArrayGetAsSeries(second);
   bool as_series_buffer=ArrayGetAsSeries(buffer);
//--- replace indexing direction with direct one if necessary
//--- calculate indicator values
   for(int i=start_index;i<rates_total;i++)
//| Custom indicator initialization function                         |
int OnInit()
//--- bind indicator buffers
//--- set indexing element in the indicator buffer
//--- check for what prices the indicator is calculated   
      //--- Open and Close prices
      //--- set the indicator color
      //--- High and Low prices
      //--- set the indicator color
//| Custom indicator iteration function                              |
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[])
//--- calculate the indicator according to the flag value
//--- return value of prev_calculated for next call

See also

Access to timeseries, ArraySetAsSeries