how to use Array

To add comments, please log in or register
Edcha
8
Edcha  

I am learning MQL4, and I do not know why when I put this code where I assign the value of an array, it takes me out of MT4 and does not print the comment, could you help me please?


double fmh[];
int numBar[];


int start()
{

     ArrayInitialize( fmh, EMPTY_VALUE);    // empty the chart
     ArrayInitialize( numBar, EMPTY_VALUE);    // empty the chart
     ResetLastError();

    fmh[0]=iHigh(NULL,0,2);
    numBar[0]=50;


   Comment(" BARS "+Bars+
          " arraySize "+ArraySize(fmh)+
          " Val High" + iHigh(NULL,0,2) ); //Report value reading



}


Could you please help me because something bad I'm doing with the array and I do not know what it is


Thanks.


Edwin Chavarria

whroeder1
17954
whroeder1  
Edcha: something bad I'm doing with the array and I do not know what it is

Your arrays have zero size, there for fmh[0] and numBar[0] do not exist. You would know that had you looked in the Experts tab.

Zee Zhou Ma
1903
Zee Zhou Ma  

Error line:

  fmh[0]=iHigh(NULL,0,2);

This is the correction needed to set the array size during initialisation:

double fmh[1];
int numBar[1];

This code will increment the arraysize of fmh to 2 when printed:

   ArrayInitialize(fmh,EMPTY_VALUE);    // empty the chart
   ArrayInitialize(numBar,EMPTY_VALUE);    // empty the chart
   ResetLastError();

   ArrayResize(fmh,2);
   
   fmh[0]=iHigh(NULL,0,2);
   numBar[0]=50;


   Comment(" BARS "+Bars+
           " arraySize "+ArraySize(fmh)+
           " Val High"+iHigh(NULL,0,2)); //Report value reading
To add comments, please log in or register