[Question] How do I handle Arrays of Arrays?

To add comments, please log in or register
Tom Wieland
23
Tom Wieland  

Code: https://gist.github.com/Industrial/71e6a771708ecd9d06ea897ec2d2319e

These lines are the (same) problem (array indexing):

Line 21

Line 28

Line 29

Line 31

Line 48

Line 50


1) Why is `double X[][];` Wrong?

2) What am I doing wrong with the array indexing?

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. Best Indicator...
nicholi shen
2335
nicholi shen  

Tom,


There's a lot to unpack here... First, you should not be resizing the indicator buffers because the platform does that automatically behind the scenes. Next, you're specifying a statically allocated matrix to be used as a dynamic buffer, which will not work. You can create objects which contain dynamic double arrays which you can register as a buffer, however, since you're still learning, it'd be best to stick with the simple method of defining individual arrays for each buffer. Furthermore, regarding the use of multiple handles and matrices, you should avoid multi-dimensional arrays unless you absolutely need them for matrix maths. MQL has high-level abstractions for your use-case that removes the hackish ambiguity of matrices when you really need OOP.  Have a look at the CIndicators library and use CiMA with a CIndicators collection. 

Tom Wieland
23
Tom Wieland  

This is my current solution: https://gist.github.com/Industrial/f5604706da6df65839fabf086d4e8290


I made individual buffers. I'm still not pleased with this. In another language I'd have easily made an objector array and stuck them in there, so I could have a dynamic amount of buffers/arrays.


I'm no longer doing the Array resizing but right now I do have a big ugly switch statement in a for loop in order to only calculate/paint the amount of lines required.


I currently have no use for matrices.

To add comments, please log in or register