Hi , when inserting one element you can refer to the code below otherwise (when insertign an array to an array) use https://www.mql5.com/en/docs/array/arrayinsert
First you resize the Array , and you add one element , you take the existing size and add one :
ArrayResize(list,ArraySize(list)+1,0);
Then you self copy , it works , with ArrayCopy .You copy all the elements of the array -1 starting from position 1 on the destination array but only if the ArraySize is >1
if(ArraySize(list)>1){ ArrayCopy(list,list,1,0,ArraySize(list)-1); }
Then you can insert your new element in slot [0] of the list
- www.mql5.com
Hi , when inserting one element you can refer to the code below otherwise (when insertign an array to an array) use https://www.mql5.com/en/docs/array/arrayinsert
First you resize the Array , and you add one element , you take the existing size and add one :
Then you self copy , it works , with ArrayCopy .You copy all the elements of the array -1 starting from position 1 on the destination array but only if the ArraySize is >1
Then you can insert your new element in slot [0] of the list
Thank you!
Hi , when inserting one element you can refer to the code below otherwise (when insertign an array to an array) use https://www.mql5.com/en/docs/array/arrayinsert
First you resize the Array , and you add one element , you take the existing size and add one :
Then you self copy , it works , with ArrayCopy .You copy all the elements of the array -1 starting from position 1 on the destination array but only if the ArraySize is >1
Then you can insert your new element in slot [0] of the list
Am I the only one doing this?😄
int arrSize = ArraySize(trends); if(!resize(arrSize - 1) // Remove trends[oneLessThanArrSize] || !setAsSeries(false) || !resize(arrSize) // Add trends[0] || !setAsSeries(true)) // Set AS_SERIES back to true return(false); trends[0].write(...);
Above is a piece that I copied from real code. I think the meaning should be clear.
This example assumes the array has AS_SERIES = true. resize() and setAsSeries() are wrapper methods for ArrayResize and ArraySetAsSeries.
I will later make and post here an example code that can be run
[EDITED]
I didn't understand the task correctly. The code snippet above adds a new value and removes a value from the opposite end of the array. That is, the array size remains the same
Am I the only one doing this?😄
Above is a piece that I copied from real code. I think the meaning should be clear.
This example assumes the array has AS_SERIES = true. resize() and setAsSeries() are wrapper methods for ArrayResize and ArraySetAsSeries.
I will later make and post here an example code that can be run
[EDITED]
I didn't understand the task correctly. The code snippet above adds a new value and removes a value from the opposite end of the array. That is, the array size remains the same
You are using a ring buffer
I just googled what a ring buffer is. Yes, it's very similar to a ring buffer.
I came up with this when I didn't want to copy the elements of a struct array.
Now I will know about ring buffer, thank you :)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I want to insert new int value in the [0] location and that the exsisting [0] location will be moved to [1] etc...
I went though the docs and i havent found a way to do this..
Does anyone know of a way? or have a code that he can share for it?
Cuz i dont want to have a for loop..