hello mql5 guru. I have such a kind of not the most difficult task but I have been fighting for a long time and do not want to go skiing)). there is an array with bid prices of a certain size. When you get the price, you need to write the new price to the beginning of the array, and move the previous values with the removal of the last ones while maintaining the size of the array. Tried and through arraycopy although it seems to be a bad method and through the loop I try to overwrite the values with an offset in the loop and does not work, knocks out the error: “Array out of range”.
Here is one of the options as I try to do. Please advise what to correct or how to do it normally in a different way to solve the problem.
for(int i = BufferSize - 1; i > 0; i--) {
Buffer[i] = Buffer[i-1];
}
Buffer[0] = NewBidPrice;
viktorternovskiy
It worked, thank you)) Although before that I also tried, but apparently I messed up somewhere. Later, I will probably rewrite it in a ring array, it will be more correct as far as I understand.
rosomah
You can use arraycopy…
ArrayCopy(
Buffer, / / where to copy
Buffer, / / from where we copy
1, / / from which index we write to the receiver
0, / / from which index we copy from the source
bufferSize-1 // how many elements
);
Buffer[0]=NewBidPrice;
nektomk
use a cyclic buffer and you won’t need to copy anything