What Buffer Types can I use in MQL4?

Steve
62
Steve  

Hi,

When I try to create an Array Buffer of type 'int' I get the compilation error "'SetIndexBuffer' - no one of the overloads can be applied to the function call":

#property version   "1.00"
#property strict

#property indicator_separate_window
#property indicator_buffers 1

int BufferIndex[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,BufferIndex);
   SetIndexStyle(0,DRAW_HISTOGRAM,EMPTY,3,clrBlue);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   int i,j,limit;
   limit=rates_total-prev_calculated;
   
   for (i=0; i<limit; i++)
     {
      BufferIndex[i]=i; // store integers in array buffer
     }
   //--- return value of prev_calculated for next call
   return(rates_total);
  }

However, if I change the array type to 'double' it compiles, like so:

double BufferIndex[];

Questions:

1. Why does the 'int' form fail compilation?

2. Which data types can I create an array of? I thought I could create arrays of many types, e.g. double, int, string, bool, etc.

3. If I have the wrong syntax to create an int array[], how do I do it correctly?

Thanks.

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
Steve
62
Steve  
Following on:

The Example given from the "ArrayDimension" MQL Help page clearly shows an array of integers being created (2-dimensional, even).

void OnStart() 
  { 
   int num_array[10][5]; 
   int dim_size=ArrayDimension(num_array);// dim_size=2 
   Print("Dimension of num_array=",dim_size);  
  }

Is my error the fact that I created it in the global scope? (I didn't think that would be a problem).

Paul Anscombe
6270
Paul Anscombe  
Steve:

Hi,

When I try to create an Array Buffer of type 'int' I get the compilation error "'SetIndexBuffer' - no one of the overloads can be applied to the function call":

However, if I change the array type to 'double' it compiles, like so:

Questions:

1. Why does the 'int' form fail compilation?

2. Which data types can I create an array of? I thought I could create arrays of many types, e.g. double, int, string, bool, etc.

3. If I have the wrong syntax to create an int array[], how do I do it correctly?

Thanks.

Buffer arrays have to be type double 

You can have integer arrays just not for use as buffers

https://docs.mql4.com/customind/setindexbuffer

SetIndexBuffer - Custom Indicators - MQL4 Reference
SetIndexBuffer - Custom Indicators - MQL4 Reference
  • docs.mql4.com
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...
Steve
62
Steve  
Paul Anscombe:

Buffer arrays have to be type double 

You can have integer arrays just not for use as buffers

https://docs.mql4.com/customind/setindexbuffer

Thank you Paul...so it seems I am yet to learn the difference between an Array and a Buffer...

Guess I have some more reading to do.