How to declare dynamic arrays

 

I really looked everywhere but I can’t sort it out.

Could you tell me why a code like this one

int Array[][15][15];
Array[1][1][1]=256;
Print(Array[1][1][1]);

is giving “Array out of range” error?

All my researches bring me to “Dynamic Array Object” on MQL5 references, which doesn’t seem to explain the situation to me.

The problem is probably on declaring the array.

Please if you can’t bother to answer to this novice, just send me a link !!!

Thanks a lot in advance

 
You should use ArrayResize function
Documentation on MQL5: Array Functions / ArrayResize
  • www.mql5.com
Array Functions / ArrayResize - Documentation on MQL5
 
claudio:

I really looked everywhere but I can’t sort it out.

Could you tell me why a code like this one

is giving “Array out of range” error?

All my researches bring me to “Dynamic Array Object” on MQL5 references, which doesn’t seem to explain the situation to me.

The problem is probably on declaring the array.

Please if you can’t bother to answer to this novice, just send me a link !!!

Thanks a lot in advance

Maybe try this:

 int Array[1][15][15];
Array[1][1][1]=256;
Print(Array[1][1][1]);

 

 
ToolMaker:

Maybe try this:

 int Array[1][15][15];
Array[1][1][1]=256;
Print(Array[1][1][1]);

 

Thank you ToolMaker, but actually here the title is
“How to declare dynamic arrays”
 
claudio:
Thank you ToolMaker, but actually here the title is
“How to declare dynamic arrays”

maybe.

int Array[1][15][15]; 

Array[0][1][1]=256; 

Print(Array[0][1][1]) ;

Is that better? 

but I thought this array is static... 

 
All that you need to know to declare dynamic array are described here (https://www.mql5.com/en/docs/basis/types/dynamic_array). There are some small example.
Documentation on MQL5: Language Basics / Data Types / Dynamic Array Object
  • www.mql5.com
Language Basics / Data Types / Dynamic Array Object - Documentation on MQL5
 

This is a slight change of subject -

I know arrays can't act as input variables however I want to know if there is a way to store them externally. At the moment I have an array that is written to in the OnCalculate section, but I can't see how to save the results from tick to tick.

Reason: