Questions from Beginners MQL5 MT5 MetaTrader 5 - page 114

 
Yedelkin:
I find it hard to answer. I re-read your messages but didn't get the idea of changing the array's size. Your answer to the code also depends on understanding the concept. Maybe somebody else will answer.

I don't really care about changing the size of the array, I'll give it 20, for example.

 double masCenPoc[20]; 

 for(int i=0; i<20; i++){
 
   if((cena_poc < high && cena_poc < low)||(cena_poc > high && cena_poc > low))

//как вот дальше обозначить чтоб он запомнил значение цены уровня Рос?
    
    masCenPoc[i] = cena_poc;

else 

//и удалил значение из массива, если нашлось пересечение с ценой этого уровня Рос?
 
Top2n: I don't really care about changing the size of the array; I'll set it to, for example, 20.

Here you have an array of 20 elements. Let's assume that the if condition holds - we assign a price value to the first element of the array: masCenPoc[0] = cena_poc;

What will we assign to the second element of the array?

 
Yedelkin:

Here you have an array of 20 elements. Let's assume that the if condition holds - we assign a price value to the first element of the array: masCenPoc[0] = cena_poc;

What should we assign to the second element of the array?

The next value of Ros which will be in n amount of time. The Ros lines appear at the beginning of each day, based on the results of the previous day. If the price does not touch the level, the value of this Ros level will be stored in the array.
 
Top2n: The next value of Ros, which will be in n amount of time. The Ros lines appear at the beginning of each day, based on the previous day's results. If price does not touch the level, then the value of this Ros level will be stored in the array.
I see. I would do the following. I would create an array of 20 elements and assign value -1 to all of them. At the beginning of each day, I would run the loop for(int i=0; i<20; i++) and look for the first element with value -1 in the array. After finding such an element, it would check trade conditions(if((cena_poc < high && cena_poc < low)||(cena_poc > high && cena_poc > low)) and if successful, assign value of cena_poc to the found array element. This would gradually fill the array with the required values.
 
Top2n: I see, thank you.
Yes, if you use a non-dynamic array (as in your last example), you don't need this function either. If you need a dynamic array, declare and size it in the first lines of code, before the loop.
 
Top2n:

I don't really care about changing the size of the array, I'll give it 20, for example.

It has to make sense. In this case, an array may not be necessary. In one loop with further calculations, maybe 1 variable is enough. I think you want to get history data, therefore it would be more logical to loop from some bar to 0. And then your data will be built. If you need an array, it should accumulate as a stack in your case.

If you want to build by online quotes, then it is still according to stack rules.

//Удачи!
 

Hello. When I try to copy indicator data to an array using the CopyBuffer function I get values like -6.99999999999999999e-005

What can be the reason?


Документация по MQL5: Доступ к таймсериям и индикаторам / CopyBuffer
Документация по MQL5: Доступ к таймсериям и индикаторам / CopyBuffer
  • www.mql5.com
Доступ к таймсериям и индикаторам / CopyBuffer - Документация по MQL5
 
sss20192:

Hello. When I try to copy indicator data to an array using the CopyBuffer function I get values like -6.99999999999999999e-005

What can be the reason?


Maybe the values are the same as in the original. It would be a good idea to post the code.
 

The indicator has different data in the data window. I attach the EA to the H1 chart and it copies the data from the M5 M15 and H1 timeframes.

int MacdHandleTf1 = iMACD(_Symbol, Timeframe1, FastEMA, SlowEMA, SignalMA, AppliedPrice); 

int MacdHandleTf2 = iMACD(_Symbol, Timeframe2, FastEMA, SlowEMA, SignalMA, AppliedPrice); 

int MacdHandleTf3 = iMACD(_Symbol, Timeframe3, FastEMA, SlowEMA, SignalMA, AppliedPrice); 

CopyBuffer(MacdHandleTf1, 0, 1, 1, MacdArray);

Print(NormalizeDouble(MacdArray[0], 5)); 

CopyBuffer(MacdHandleTf2, 0, 1, 1, MacdArray);

Print(NormalizeDouble(MacdArray[0], 5)); 

CopyBuffer(MacdHandleTf3, 0, 1, 1, MacdArray); 

Print(NormalizeDouble(MacdArray[0], 5)); 
Reason: