Errors, bugs, questions - page 512

 
Neofit:
Setthe size of the array. ArrayResize
 
Neofit:

Please advise how to work correctly with an array which elements are Mqlrates structures.

This is exactly what I want to know:

MqlRates AdaptedRates[];

ArraySetAsSeries(AdaptedRates,true); 

AdaptedRates[300].open=1;

The debugger gives an error - Invalid array access.

I understand that using this form of recording, we can only read elements of a structure which is an element of an array.

The question is how to write the structure elements correctly. I am not interested in all of them. The important thing is the price of .open .high .low .close.

I apologize in advance for this question probably very trivial (I'm not the programmer), but help I have not found the answer. I will be grateful for any help.

You are using a dynamic array AdaptedRates[]. As far as I remember, when working with dynamic arrays, their size should be set using ArrayResize() function. But so far the compiler has complained about index 300 specified in the third line.
 
Swan:
Set the size of the array. ArrayResize
As far as I understand, if I set the size, for example
MqlRates AdaptedRates[302];  
I can't set the type of indexing as series.
 
Neofit:
As far as I understand, if I define size, for example
MqlRates AdaptedRates[302];  
I won't be able to set indexing type as series.

:) You don't set static array, but set dynamic array size with ArrayResize().

Well, like: ArrayResize(AdaptedRates,302); etc.

 
Yedelkin:
You are using a dynamic array AdaptedRates[]. As far as I remember, when working with dynamic arrays you should set their size using the ArrayResize() function. And so far the compiler is crashing on index 300 specified in the third line.
Static arrays cannot be represented as timeseries, i.e. the ArraySetAsSeries() function, which sets access to array elements from the end of the array to its start, is not applicable to them. If you want to provide access to an array as in timeseries, use a dynamic array object.

This is a quote from the help.

Swan, Yedelkin thanks for such a quick response.

 
Neofit:
As far as I understand, if I define a size, for example
MqlRates AdaptedRates[302];  
I can't set the indexing type as series.

yes.

MqlRates AdaptedRates[];//thereby leave the array dynamic

ArrayResize(AdaptedRates,302);//and set the right size

Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура исторических данных
Документация по MQL5: Стандартные константы, перечисления и структуры / Структуры данных / Структура исторических данных
  • www.mql5.com
Стандартные константы, перечисления и структуры / Структуры данных / Структура исторических данных - Документация по MQL5
 
Yedelkin:

:) You don't set a static array, but set a dynamic one using ArrayResize().

Well, like ArrayResize(AdaptedRates,302); etc.

Thanks for the popular explanation, as far as I understand it is advisable toArrayResize itto the right limits before any reference to a dynamic array cell, I will try it.
 
pusheax:

A glitch in the strategy tester.

It suddenly stops and all local and remote agents have finished and so hangs.

Can you tell me how to start it again, it's a shame to start all over again?
I do it regularly :-) I can't start it again, I disable clouds and then launch clouds again. It's worse, when it happens at night, it stays on until I wake up :-)
 
Neofit:
Thanks for the popular explanation, as far as I understand it is desirable to ArrayResize it to the required limits before any reference to a dynamic array cell , I will try it.

Note. Only for indicator buffers this will not need to be done. The executive subsystem of the terminal handles this by itself.

Note 2:ArrayResize() should preferably be applied only when it is necessary to change the size of a dynamic array, and not before any access to its elements. It may well be that a dynamic array will be given a size once, and then the program will simply access its items.

 
Yedelkin:

Note. Only for indicator buffers this will not need to be done. The executive subsystem of the terminal handles this by itself.

Note 2:ArrayResize() should preferably be applied only when it is necessary to change the size of a dynamic array, and not before any access to its elements. It may well be that a dynamic array will be sized once and then the program will simply access its elements.

Well, I'm being silly to say so, actually I understand that if I've already expanded a dynamic array to 302, I can access any element from 0 to 301 without ArrayResize.