Either you use a fixed array:
double DR[100];
OR you have to ste the lenght before you use it:
double DR[];
ArraySize(DR,100);
ArrayResize(DR,100);
Either you use a fixed array:
OR you have to ste the lenght before you use it:
Using a fixed array is what I tried in the first box:
double Limit=Bars-1; double DR[Limit]; for(i=Bars-1; i>=0; i--) { DR[i]=Close[i]-Open[i]; // daily return Alert("Daily return of bar ", i, " = ",DR[i]); }
Are you saying that I cannot use a variable in the above, but only a constant?
ArraySize(DR,100);
The above returns the error 'wrong parameters count'
It appears that 'ArraySize' simply returns the number of elements in an array, rather than allowing you to define the required number of elements with a variable.
Yes, that's correct. ArraySize() does not allocate.
For dynamically allocating an array, you want ArrayResize().
The above returns the error "invalid index value" in the highlighted position.
The above cannot load in the terminal due to the array being 'out of range'
This is the first time I have had to declare/define a user-defined array so I apologise if this is ultra-basic to the reader, but I can't see what I'm doing wrong.
In the first situation, I have declared the number of elements (as is shown in the manual: https://book.mql4.com/variables/arrays)
In the second situation, I have left the number of elements undeclared, and 'i' is out of range. How can this be when the value of 'i' is dependant upon Bars-1?
Yes, that's correct. ArraySize() does not allocate.
For dynamically allocating an array, you want ArrayResize().
Thanks.
Could you please post in the right section, don't you see that each time we have to move your topic to mql4 section ?
No I hadn't noticed.
No I hadn't noticed.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The above returns the error "invalid index value" in the highlighted position.
The above cannot load in the terminal due to the array being 'out of range'
This is the first time I have had to declare/define a user-defined array so I apologise if this is ultra-basic to the reader, but I can't see what I'm doing wrong.
In the first situation, I have declared the number of elements (as is shown in the manual: https://book.mql4.com/variables/arrays)
In the second situation, I have left the number of elements undeclared, and 'i' is out of range. How can this be when the value of 'i' is dependant upon Bars-1?