With a dynamically assigned array like high[], index 0 will only be the latest bar when you set that buffer as series (if more than one value is used in the buffer)
ArraySetAsSeries(high, false); // has no effect because the array is array-based by default and not series-based
That's correct
but to address this:
"index=0 means latest bar - ALWAYS?"
no, not when there is more than one value used, so you have to explicitly set the series then:
double high[]; ArrayResize(high, numberOfBars); ArraySetAsSeries(high, true);
Use ArrayReverse if you want to reverse the elements. I don't know why you would want to though in an EA.
- www.mql5.com
but to address this:
"index=0 means latest bar - ALWAYS?"
no, not when there is more than one value used, so you have to explicitly set the series then:
Use ArrayReverse if you want to reverse the elements. I don't know why you would want to though in an EA.
You misunderstood the question.
Let me put the question more clearly:
Is there a way to tell GetData() or CopyBuffer() to start from the left instead of the right when copying the data into the returned array? The specified index (=start_pos) is an array-based index (i.e., the index is not from a time series-based array). Now I want to use this index (e.g., 0, which should point to the first bar in the series, not the last, etc.). It is clear that the resulting array is by default array based and not series based (which is fine for my use case!). I only operate in array-based indices.The problem is, the method accepts an index which is series based.
int CopyBuffer( int indicator_handle, // indicator handle int buffer_num, // indicator buffer number int start_pos, // start position (excepts always (?) a series based index, i.e. 0 means latest bar) int count, // amount to copy double buffer[] // target array to copy );
CopyBuffer reads an array as it is. You don't concern yourself with how copybuffer copies data. It's the array itself that you care about. The left-to-right filling in CopyBuffer is independent of how you use the array...
- 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 have an array-based index (i.e., the index comes not from a time series based array). Now I want to use this index:
However, since buffer access is series-based (see https://www.mql5.com/en/docs/series/copybuffer), the specified index must also be series-based (i.e., if index = 3, I get the 3rd bar from the right). The resulting array high[] is still array-based (i.e., the oldest element is at the beginning) which is what I need.
Is there a way to tell GetData() or CopyBuffer() to start from the left instead of the right?
Something like this does not work: