Array out of bound exception thrown when accessing multidimensional (2d) array inside OnCalculate

 

Source Code:

https://pastebin.com/Tv7BELjw


I have met array out of bound exception while accessing 2d-array inside OnCalculate. But once I changed line 39 to

S[0][0].Data[k] = i * 2 + j;

, that is, access only the (0,0) element, the exception is no longer thrown.


I believe this is a compiler bug or some feature not documented.


Reproduce procedure:

Put https://pastebin.com/Tv7BELjw into an indicator and run the indicator.

Change line 39 to S[0][0].Data[k] = i * 2 + j; and rerun the indicator.


Expected behavior:

S[i][j].Data[k] = i * 2 + j; would not throw exception.


Related Topic:

https://www.mql5.com/en/forum/305638

通过MQL5社区和服务探索MetaTrader 5的新机遇
通过MQL5社区和服务探索MetaTrader 5的新机遇
  • www.mql5.com
MQL5:MetaTrader 5客户端内置的交易策略语言。语言允许编写您自己的自动交易系统,技术指标,脚本和函数程序库
 
multidimensional array: Out of Range
multidimensional array: Out of Range
  • 2019.03.05
  • www.mql5.com
Dear, I would like to contrast DIs (ADX) with different averaging time frame , so I created a custom Indicator using the basics of ADX Wilder Movin...
 
You have to specify the amount of buffers the indicator will use, it is working on [0][0] because by default, indicators have 1 buffer, add the following:

#property indicator_buffers 4
 
Alexandre Borela #:
You have to specify the amount of buffers the indicator will use, it is working on [0][0] because by default, indicators have 1 buffer, add the following:

Thank you very much. I have forgotten the 
#property indicator_buffers 4


Wish you all a great day! Also thank you for your help!

Array out of bound exception thrown when accessing multidimensional (2d) array inside OnCalculate
Array out of bound exception thrown when accessing multidimensional (2d) array inside OnCalculate
  • 2021.09.13
  • www.mql5.com
Source Code: https://pastebin.com/Tv7BELjw I have met array out of bound exception while accessing 2d-array inside OnCalculate...
Reason: