[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 131

 
Vinin:

Continuation of the theme

Previous here https://www.mql5.com/ru/forum/111497

In the MT4 tester in the optimization results and optimization graphs nothing is displayed, just empty. Help!
 
Sergey_Rogozin:

I'm trying to fill a one-dimensional array ValueArr[].

I'm not sure if it's correct.

On each tick GetValue() function outputs an int value. How do I fill ValueArr[]?

Is my attempt correct?

The array's size should be increased by one on each tick? Then its size will be limited by available computer memory.

Increase the size of the array ValueArr[] using the function ArrayResize() and append the new data into the array. Again - where do you want to add them? At the beginning or at the end?

If at the beginning, you need to move previously written data, otherwise they will be overwritten by the newly written data.

If at the end, then:

Inite set array size = zero, and at start increase it by 1 (size++), then resize the array ( ArrayResize(ValueArr, size);) and write data into cell ValueArr[] indexed by size-1 (ValueArr[size-1]), obtained by GetValue(); (ValueArr[size-1]=GetValue();).

 
artmedia70:

Do you want the size of the array to increase by one on every tick? Then its size will be limited by available computer memory.

At every tick, increase the size of array ValueArr[] using function ArrayResize() and append new data into the array. Again - where do you want to add them? At the beginning or at the end?

If at the beginning, you need to move previously written data, otherwise they will be overwritten by the newly written data.

Inite set array size = zero, and at start increase it by 1 (size++), then resize the array ArrayResize(ValueArr, size); and append data obtained by GetValue() function into ValueArr[] array cell indexed by size-1 (ValueArr[size-1]);

Yes, the data from GetValue() will be written on every tick to ValueArr[] array.

The size of the array is increased with every tick, but it can be defined at once, say, [10000].


Elements of the array are arranged in the order of arrival, i.e., the first written element is the first in the "general queue",

the second element is second in the queue.


If I understood correctly, it looks like this:


 int size=0;
 int ValueArr[size];
 
//-----------------

int start()
 {
   size++;
   ArrayResize(ValueArr, size);
   ValueArr[size-1] = GetValue();
   
 return();
 }

//-----------------

int GetValue()
 {
 .......
 return(Val);
 }

I hope I have understood you correctly.

 
Sergey_Rogozin:

The elements of the array are arranged in order of arrival, i.e. the first one written is first in the "general queue",

why not use a timeseries array
 
eddy:
why not use a timeseries array?
A timeseries? Is there any way this could help in recording something like teak history?
 
Sergey_Rogozin:

I'm trying to fill a one-dimensional array ValueArr[].

I'm not sure if it's correct.

On each tick GetValue() function outputs an int value. How do I fill ValueArr[]?

Is my attempt correct?

So
 int ValueArr[size]; 

you cannot. When declaring an array, you either specify a constant as the size or nothing, and the array is then considered dynamic.

The correct way is this

int ValueArr[]; 

int init()
{
   ArrayResize(ValueArr,size);
}
 
teak - no
 

Please advise! Is there a function in MT4, which would take into account the result of a previous trade to open a new one? If yes, how can I specify it correctly?

 
sto_mat:

Please advise! Is there a function in MT4, which would take into account the result of a previous trade to open a new one? If yes, how can I specify it correctly?


There is no such built-in function, you have to write it yourself, I showed an example here:https://www.mql5.com/ru/forum/131277/page113
 
alsu:
This is

you can't. When declaring an array, either a constant is specified as a size, or nothing, and the array is then considered dynamic.

The correct way is this


Then I guess that's it:

 int size, ValueArr[]; 
//-----------------
 int init()
 {
   ArrayResize(ValueArr,size);
 }
//-----------------

int start()
 {
   ValueArr[size-1] = GetValue();
 return();
 }

//-----------------

int GetValue()
 {
 .......
 return(Val);
 }

Is this right?