I have the following code as below, the issue is when I run it it says array out of range, can someone help me, I am trying to learn MQL5. Thanks in advance
- array out of range when I try to use
- Indicator Miscellaneous Questions
- Array out of Range. PLEASE HELP
Jones John: I have the following code as below, the issue is when I run it it says array out of range, can someone help me, I am trying to learn MQL5. Thanks in advance
Array index starts at 0, not 1, and the size of the first dimension should be 2 and not 1.
string array_check() { string array1[2,4]; array1[0,0]="AA"; array1[0,1]="BB"; array1[0,2]="CC"; array1[0,3]="DD"; array1[1,0]="AA1"; array1[1,1]="BB1"; array1[1,2]="CC1"; array1[1,3]="DD1"; string result=array1[0,1]; return result; }
Jones John #: And if I may ask Fernado, what if I wanted to put the array1[0] all inputs in one line?
string array_check() { static string array1[ 2, 4 ] = { { "AA", "BB", "CC", "DD" }, { "AA1", "BB1", "CC1", "DD1" } }; string result = array1[ 0, 1 ]; return result; };The use of "static" is so that it only initialises the array once and not on every call to the function.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register