I am trying to play with the storage of the MQL 5 Array. When I am not using any ArrayResize()
, I am getting error:
double d [];
d[0] = 1;
for (int i = 0; i< ArraySize(d); i++)
{
Print(d[i]);
The error is as follows:
2018.03.26 13:17:25.379 2018.02.02 00:00:00 array out of range in 'testing.mq5' (69,2)
Whereas when I use ArrayResize()
I get output.
double d [];
ArrayResize(d,2);
d[0] = 1;
for (int i = 0; i< ArraySize(d); i++)
{
Print(d[i]);
}
Output: 1
It worked. But, if I try to add the array element beyond the array size then I get out of range
error.
I am will to achieve is that the array must remain dynamic in size perspective.
Say I the size given is 2
and during my program the array element at 3
needs to be added then the array must accept it.
I cannot use ArrayResize()
as it will wipe out other values, which I don't want to happen.
Kindly, suggest me a middle way out so that I can enter any number of values in an array irrespective of its size.