Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to code a Multidimensional Dynamic Array?

How to code a Multidimensional Dynamic Array in MQL4? I'm fairly new to coding MQL4. Currently coding my first EA and just learnt about Arrays. I was wondering, how to code a dynamic array?

What I'm trying to do is when my EA is initialized, for the past 100 bars, find out the Highest 50 bars and save and name them accordingly, then out of the 50 bars, find out the top 10 with the Highest Trading Volume and save them and name them again. I'm thinking using dynamic array to save the bars but I don't know how to do it.

like image 527
laman Avatar asked Feb 12 '26 12:02

laman


1 Answers

Nothing special, just using regular tools:

double array[][2];
int    size = 100;

void FunctionArray(){
     ArrayResize( array, size );
     for( int i = 0; i < size; i++ ){
          array[i][0] =          iHigh(   _Symbol, 0, i );
          array[i][1] = (double) iVolume( _Symbol, 0, i );
     }

// Print( __LINE__, " ", array[0][0], " ", array[1][0], " ", array[2][0], " ", array[3][1], " ", array[size-1][0], " ", array[size-1][1] );

   ArraySort( array, WHOLE_ARRAY, 0, MODE_DESCEND );

// Print( __LINE__, " ", array[0][0], " ", array[0][1] );

   double     new50Array[50][2];
   ArrayCopy( new50Array, array, 0, 0, size );          // block-copying

// Print( __LINE__, " ", array[0][0], " ", array[0][1], " ", array[1][0], " ", array[1][1], " ", array[49][0], " ", array[49][1] );
   }

and same for volumes - you need to develop own tool as ArraySort() is running only for the first element;
alternatively - copy by element into a new50Array[][]
but iVolume() at first place
and iHigh() at second,
instead of 'copying', and then call ArraySort() again

like image 65
Daniel Kniaz Avatar answered Feb 15 '26 07:02

Daniel Kniaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!