Unexpected indexing when using iBarShift() in sample print statements.

 

Somehow when printing out iBarShift() it appears to be going in reverse order from high to low while our time is being printed from past to present. We are sending in the most recent time and getting back the lowest index in our indicator buffer (obvBuffer[]) . We would expect the current index to be the highest as our indicator processes data from left to right. We have triple checked the indexing direction https://www.mql5.com/en/docs/series/bufferdirection and iBarShift https://www.mql5.com/en/docs/series/ibarshift details a few times but not seeing what im missing. Thanks for any insights and help understanding these details. 

Documentation on MQL5: Timeseries and Indicators Access / Indexing Direction in Arrays, Buffers and Timeseries
Documentation on MQL5: Timeseries and Indicators Access / Indexing Direction in Arrays, Buffers and Timeseries
  • www.mql5.com
Indexing Direction in Arrays, Buffers and Timeseries - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
 
Joshua McGowan: Somehow when printing out iBarShift() it appears to be going in reverse order from high to low while our time is being printed from past to present. We are sending in the most recent time and getting back the lowest index in our indicator buffer (obvBuffer[]) . We would expect the current index to be the highest as our indicator processes data from left to right. We have triple checked the indexing direction https://www.mql5.com/en/docs/series/bufferdirection and iBarShift https://www.mql5.com/en/docs/series/ibarshift details a few times but not seeing what im missing. Thanks for any insights and help understanding these details. 

iBarShift() as well as other time-series functions treats the data as a series array where the current bar is located at index/shift [0].

In contrast, for MQL5 by default, the OnCalculate() event handler, presents the argument data as a non-series array where the current bar is index/shift [rates_total-1].

This is explained in the very documentation you have linked where it is explained that you should be using the ArrayGetAsSeries() to find out which form is being used and/or to set the form you wish to use with ArraySetAsSeries().

As a side note, the default for OnCalculate() in MQL4 is however the opposite to MQL5, where it is treated as as series array.
 
Fernando Carreiro #:

iBarShift() as well as other time-series functions treats the data as a series array where the current bar is located at index/shift [0].

In contrast, for MQL5, by default the OnCalculate() event handler, presents the argument data as a non-series array where the current bar is index/shift [rates_total-1].

This is explained in the very documentation you have linked where it is explained that you should be using the ArrayGetAsSeries() to find out the which form is being used and/or to set the form you wish to use with ArraySetAsSeries().

As a side note, the default for OnCalculate() in MQL4 is however the opposite to MQL5, where it is treated as as series array.

Ah and I even remember you commenting on one of the threads I was digging thru. Ugh if it was a snake id be bitten about 33 times haha. Very much appreciated and hope one day to contribute as much as you all have to this community. Thank you sir :) Muito Obrigado Fernando!

 
Joshua McGowan #: Ah and I even remember you commenting on one of the threads I was digging thru. Ugh if it was a snake id be bitten about 33 times haha. Very much appreciated and hope one day to contribute as much as you all have to this community. Thank you sir :) Muito Obrigado Fernando!
You are welcome!
 
Fernando Carreiro #:

iBarShift() as well as other time-series functions treats the data as a series array where the current bar is located at index/shift [0].

In contrast, for MQL5, by default the OnCalculate() event handler, presents the argument data as a non-series array where the current bar is index/shift [rates_total-1].

This is explained in the very documentation you have linked where it is explained that you should be using the ArrayGetAsSeries() to find out the which form is being used and/or to set the form you wish to use with ArraySetAsSeries().

As a side note, the default for OnCalculate() in MQL4 is however the opposite to MQL5, where it is treated as as series array.

Hey Fernando, Again thank you for taking the time to reply to this, very much appreciated. I had a chance to sit down with my partner and try what you suggested but realized that the issue doesn't appear to be with the arrays. When we send in a value from time[] things earlier in the array are coming back with higher numbers and current bars are coming back lower. We have double checked the time array is not a series, as shown by the false flag, we've double checked the obvBuffer[] is also not set as series and matches up with time[] in that regard. While we could potentially solve this by setting these arrays to series this would require a through rework and would like to understand why this is happening. 

Files:
Reason: