double Array1[5]= {0,1,2,3,4,5};
The array has 5 elements, your initialization contains 6. Either use the correct size, correct initialization, or have mql4 compute it.double Array1[]= {0,1,2,3,4,5}; // has 6 elements Array1[4] == 4
double Array1[]; // Has no elements Array1[0]= {0}; // This shouldn't compile because of the braces. Alert(Array1[4]); // 0 because Array1 has no elements
This you can NOT do. Array has ZERO length. You must resize arrays:double Array1[]; // Has no elements ArrayResize(Array1, 5); // Now has 5 elements Array1[0]= 0; : Array1[4]= 4; Alert(Array1[4]); // 4
It works now. Thanks WHReoder :)
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
Hi guys,
I know this may seem like a really easy question but I've been struggling with using Arrays. I've write some code with variables which work but now I want to learn to use Arrays as my next code requires me to use an unknown number of variables (expected to be large). I'm hoping Arrays can solve that problem.
Could someone please help?
I've written the follow, which works, I get the number 4.
However, I was wondering why the follow doesn't work: (I was expecting to get the number 4 too, however, i get 0)