Trader’s Tech – Writing Your Own EA Part 71 – Arrays

If you’re new to this series and want to check it out from the beginning, you can find that here. And look herefor a list of all the programming articles.

In Part 70 we continued our discussion of MQL4’s built-in array functions. In this installment we’ll begin our discussion of multi-dimensional arrays.

For the last several installments we’ve been talking about arrays. More specifically, single-dimension arrays. A single-dimension array has a single subscript or index following the array name contained in square brackets. A two-dimension array has two indices following the array name (for example, Prices[10,10].) A two-dimension array can be thought of like a spread sheet. You can think of the two indices like the rows and columns of a spreadsheet.

Likewise, a three-dimension array (Prices[10,10,10]) can be thought of like a stack of spreadsheets, rows, columns and sheet numbers. Four-dimension arrays (Prices[10,10,10,10]) are conceptually a little more difficult. MQL4 allows a maximum of four dimensional arrays. For the purposes of this article series, we will stick to one- and two-dimensional arrays.

All elements of the array must be of the same declared variable type. In other words, all the elements must be string, integer, double or some other MQL4-recognized variable type. You can manipulate your way around this by declaring the array as type string and then using the string conversion functions (DoubleToStr(), StrToDouble() and TimeToStr(), StrToTime(), etc.) to convert the stored string elements to whatever variable type you require.

The indices of a multi-dimensional array can be notated in two different ways, according to your preference. You can separate the indices using a comma (Prices[10,10]), or each index can be contained in it’s own set of square brackets (Prices[10][10]). I prefer the commas since they are quicker and easier to type, but as I say, use your personal preference.

One very nice feature about arrays is the ability to write the array to and read the array from a file with a single command:

Disclaimer: Trading forex on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts.

WINNERS EDGE TRADING

DOUBLE TREND TRAP STRATEGY

Do You Need aProfitable Trading Strategy?

FINAL STEP

Where Should We Send youOur Double Trend Trap Strategy?

WE WILL NEVER SPAM YOU

GREAT JOB ON HAVING A WINNING STRATEGY!

That is very Rare Indeed.

Now Take your trading to the next level bytaking our trading quiz to pinpointyour strengths and weaknesses.