Hi
I have set a double array with the AS_SERIES flag using the ArraySetAsSeries function, but when I add a new value to array[0] the older values does not distribute to the other indexes, in fact it apears a loong number. See below the first 4 indexes
[0] 3315.0 (this is right)
[1] 9.881312916824931e-324
[2] 9.881312916824931e-324
[3] 9.881312916824931e-324
am I doing something wrong?
It is a dynamic array, and I'm using the ArrayResize function to add one index before througing any new values.
Thank you
If you need to append an array with a new value, then that element always goes to the end. You might find it much easier to use the std lib array class instead where you can insert an element at a specified index and the remainder of the array adjusts to accommodate the new element.
#include <Arrays\ArrayDouble.mqh> void OnStart() { double test_numbers[] = {1.,2.,3.,4.,5.}; CArrayDouble array; array.AssignArray(test_numbers); array.Insert(0., 0); for(int i=0;i<array.Total();i++) printf("%f",array[i]); }https://www.mql5.com/en/docs/standardlibrary/datastructures/carraydouble

- www.mql5.com
Show your code if you need coding help.
double tops[]; ArrayResize(tops,2); ArraySetAsSeries(tops,true); tops[0] = 0; tops[1] = 0; ArrayResize(tops,ArraySize(tops) + 1); tops[0] = renko_close[0]
Like I mentioned the new element is going to always be at the end. So either you need to manually shift your entire array or use the CArrayDouble with CArrayDouble::Insert method.
...or even better just add your new value to the end of the array and loop backward instead.
Like I mentioned the new element is going to always be at the end. So either you need to manually shift your entire array or use the CArrayDouble with CArrayDouble::Insert method.
Thats not what this doc says
https://www.mql5.com/en/articles/567
Look for Array Indexing Order. It shows this example
double ar[]; // Array ArrayResize(ar,2); // Prepare the array ar[0]=1; // Set the values ar[1]=2; ArraySetAsSeries(ar,true); // Change the indexing order ArrayResize(ar,3); // Increase the array size ar[0]=3; // Set the value for the new array element Alert(ar[0]," ",ar[1]," ",ar[2]); // Print array values
"After the execution of this code, the values contained in the array should be 3, 2 and 1."

- 2013.03.11
- Dmitry Fedoseev
- www.mql5.com
Array indexing and resizing an AS_SERIES array - Indexes - MQL4 and MetaTrader 4 - MQL4 programming forum
If you need to append an array with a new value, then that element always goes to the end. You might find it much easier to use the std lib array class instead where you can insert an element at a specified index and the remainder of the array adjusts to accommodate the new element.
https://www.mql5.com/en/docs/standardlibrary/datastructures/carraydoubleThats not what this doc says
https://www.mql5.com/en/articles/567
Look for Array Indexing Order. It shows this example
"After the execution of this code, the values contained in the array should be 3, 2 and 1."
You are talking about apples and oranges. Also the code is flawed, have you tried it yourself? Because it does not do what was advertised. Ask yourself what you would have to add so that the values would shift as you want.
A tip, you can shift the values manually but when you know what you are doing you will automate it with a loop.
Other than that the article is very useful for beginners. Everybody makes mistakes. Comment to the author, I am sure he will check and correct it.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
I have set a double array with the AS_SERIES flag using the ArraySetAsSeries function, but when I add a new value to array[0] the older values does not distribute to the other indexes, in fact it apears a loong number. See below the first 4 indexes
[0] 3315.0 (this is right)
[1] 9.881312916824931e-324
[2] 9.881312916824931e-324
[3] 9.881312916824931e-324
am I doing something wrong?
It is a dynamic array, and I'm using the ArrayResize function to add one index before througing any new values.
Thank you