More about Arrays

Hi folks!

We have studied Arrays here and here. Please give them a review!
Today we are going to study an example of 2 dimensional array and a very useful code that "Using Arrays to track info for All Open Orders" (Do you hear me deeforex ?)

Arrays are tables:

The best model that the arrays are look like is the tables. You have a table that includes only your monthly profits/losses in Forex; this is one dimensional array.

For the complex data you need more columns in the table and more dimensions in the array. For example the table (array) which will hold all the opened trades information maybe looks like that:

 

OrderSwap

OrderLots

OrderTakeProfit

OrderStopLoss

OrderProfit

OrderOpenPrice

-0.68 0.10 0.00 0.00 45.97

118.01

0.00 0.10 1.8763 1.8713 6.00 1.8758
0.00 0.30 0.7531 0.7478 15.00 0.7523

 

 

 

Could you guess how much dimensions the array above have? No! It's 2 dimensional array!

"Whatever the number of the fields, whatever the number of columns, the 2 dimensional arrays are for your all purposes" Saying of mine :)!

The array above has 2 dimensions; the first dimension is the fields of the array (we have three fields in the table above). The second dimension is the columns of the array (we have 6 columns in the table above). So, in code our array will be like that:

double myarray[2][5];

No! it's not a typo! In the world of MQL4 arrays (and the most of programming language arrays) the first element of the array starts from 0. so the 3 fields and 6 columns arrays will be "myarray[2][5]" (We always subtract 1 from the total elements of the array).

Note: There are 3 dimensional arrays and 4 dimensional arrays in MQL4 but they are abandoned topics. Just for your knowledge the maximum dimension of the arrays in MQL4 is 4 dimensional arrays. 

How to access the 2 dimensional array? 

Let's MQLing!