Questions from Beginners MQL5 MT5 MetaTrader 5 - page 115

 
sss20192:

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  CopyBuffer(
   int       indicator_handle,     // handle индикатора
   int       buffer_num,           // номер буфера индикатора
   int       start_pos,            // откуда начнем 
   int       count,                // сколько копируем
   double    buffer[]              // массив, куда будут скопированы данные
   );
Buffers (you have zeros) and arrays where we copy are all the same, you start with 1 element, copy 1 element, perhaps the direction of the array also matters.

 
zfs:
Buffers (you have zeros) and arrays where you copy are all the same, you start with 1 element, copy 1 element, maybe the direction of the array also matters.

Well, yes, the first indicator buffer, on three different tamframes. And so far I'm using the same array for logging data.

I tried to set ArraySetAsSeries true and false. All the same, sometimes strange data like -4.53e-32 appear in the log.

 

Gentlemen, can you tell me how to implement this?

There is an array, a value is written to it, and if it contains a similar value, there is a bang.

 
sss20192 Sometimes strange data like -4.53e-32 appear in the log anyway
On the bright side, we should insert checks both for success of creating handles and for success of theCopyBuffer() function . Otherwise we do not even know yet if this trash value is the result of successful execution of theCopyBuffer() function or the function did not work properly.
 
Top2n: There is an array, a value is written to it, and if it contains a similar value, there is a crash.
The array elements should be searched for matches with the required value. If no matches are found, the value is written to the array.
 
Yedelkin:
You should try to search the array elements to see if they match the required value. If no match is found, write the value into the array.
And how to compare two indexes in one array?
 
Top2n:
And how to compare two indexes in one array?

Care to read the article carefully ? >> MQL5 programming basics - Arrays

It has all the details for all the cases that deal with arrays. It should definitely suffice for you. ))

 
tol64:

Care to read the article carefully ? >> MQL5 programming basics - Arrays

It has all the details for all the cases that deal with arrays. It should definitely suffice for you. ))

Thank you all for all your help!) I won't say goodbye to you)))
 
Yedelkin:
Friendly, we should insert into the code the checks for success of creating handles and for success ofCopyBuffer() function . Otherwise we do not even know if this trash value is a result of successful execution ofCopyBuffer() function or the function did not work properly.

Checked. Handles are created normally, indexes are 10, 11, 12. But CopyBuffer function generates error ERR_INDICATOR_DATA_NOT_FOUND. Why can this error occur, the selected pairs are in the Market Watch window, charts of these currency pairs are open.

Moreover, I create a variable, which shows the result of CopyBuffer execution,

int aaa = CopyBuffer..., it shows value 1, as if one value was copied, as defined in the function.


When copying the MA buffer the same error is shown, but the value is written into the array correctly.

Please show us an example of correct buffer copying

 
sss20192: Checked. The handles are created normally and they have indices 10, 11 and 12. But the CopyBuffer function generates the error ERR_INDICATOR_DATA_NOT_FOUND. Why can such an error occur, the selected pairs are in the Market Watch window, the charts of these currency pairs are open.

Furthermore, I create a variable which shows the result of CopyBuffer execution,

int aaa = CopyBuffer..., it shows value 1, as if one value was copied, as defined in the function.

When copying the MA buffer, the same error is shown, but the value is written to the array correctly.

Please show me an example of how to copy buffer correctly

Yes, the example of buffer copying is right in the description of function CopyBuffer(). Please pay attention to lines

//--- check if all data calculated
    if(BarsCalculated(ma_handle)<rates_total) 

//--- try to copy
    if(CopyBuffer(ma_handle,0,0,to_copy,MABuffer)<=0) return(0);