Hello,
i have the following array-Structure.
myarray[level1][level2]
Now i store some values
myarray[0][0]=val0_1 myarray[1][0]=val1_1 myarray[3][0]...etc.
[1]=val0_2 [1]=val1_2
[2]=val0_3 [2]=val1_3
[3]=val0_4 [3]=val1_4
etc. etc.
Now i want to delete the first element and add a new one for a single index and reindex it.
After that the result should be for Example
myarray[1][0]=val1_2 (one index up - the old value val1_1 is deleted)
[1]=val1_3 (one index up)
[2]=val1_4 (one index up)
[3]=val1_5 (this is new)
Is there any prebuild functions to do that? I want to avoid to make a loop and reorganisate it by hand (the array has up tp 1000 elemens)
Thanks a lot!
int last_index=ArraySize(array)-1; array[0]=array[last_index]; array[last_index]=new_value;
I propose this solution for one-dimensional array (in case the order is not important for you).
-
Adding elements
Array indexing and resizing an AS_SERIES array - MQL4 programming forum #2 (2017) -
Removing elements
easiest way to remove first element and at one element at the end - General - MQL5 programming forum #4 (2022) -
Remember, do not use ArraySize, use ArrayRange with a 2D.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
i have the following array-Structure.
myarray[level1][level2]
Now i store some values
myarray[0][0]=val0_1 myarray[1][0]=val1_1 myarray[3][0]...etc.
[1]=val0_2 [1]=val1_2
[2]=val0_3 [2]=val1_3
[3]=val0_4 [3]=val1_4
etc. etc.
Now i want to delete the first element and add a new one for a single index and reindex it.
After that the result should be for Example
myarray[1][0]=val1_2 (one index up - the old value val1_1 is deleted)
[1]=val1_3 (one index up)
[2]=val1_4 (one index up)
[3]=val1_5 (this is new)
Is there any prebuild functions to do that? I want to avoid to make a loop and reorganisate it by hand (the array has up tp 1000 elemens)
Thanks a lot!