Download MetaTrader 5

CopyBuffer does not work in OnInit() function ?

To add comments, please log in or register
Marcelo Coutinho
1205
Marcelo Coutinho  

Good Afternoon,

Anyone knows why I cannot use the structure below @OnInit() since it works perfectly on OnTick() ?

The idea is to check handle management BEFORE receiving the 1st tick and realise it will not work due to lack of history.

if(CopyBuffer(i_handle,0,0,6,i_buffer)!=6)
   {
    Print("Failed to copy data from the indicator buffer or price chart buffer: ",GetLastError());
    ResetLastError();
    return;
   }

Thank you and Regards,

MRC

Alain Verleyen
Moderator
33799
Alain Verleyen  
Marcelo Coutinho:

Good Afternoon,

Anyone knows why I cannot use the structure below @OnInit() since it works perfectly on OnTick() ?

The idea is to check handle management BEFORE receiving the 1st tick and realise it will not work due to lack of history.

Thank you and Regards,

MRC

And what is the problem ?
Marcelo Coutinho
1205
Marcelo Coutinho  
Alain Verleyen:
And what is the problem ?

When I place this structure @ the end of OnInit(), CopyBuffer as an integer function returns -1
ERR_INDICATOR_DATA_NOT_FOUND/ 4806/ Requested data not found

When I place the exact same structure @ the OnTick(), CopyBuffer as an integer function returns 6

Alain Verleyen
Moderator
33799
Alain Verleyen  
Marcelo Coutinho:

When I place this structure @ the end of OnInit(), CopyBuffer as an integer function returns -1

When I place the exact same structure @ the OnTick(), CopyBuffer as an integer function returns 6

-1 means there is an error, what is the error code ?

Marcelo Coutinho
1205
Marcelo Coutinho  
Alain Verleyen:

-1 means there is an error, what is the error code ?

ERR_INDICATOR_DATA_NOT_FOUND/ 4806/ Requested data not found
Henrique Vilela
1713
Henrique Vilela  
Marcelo Coutinho:
ERR_INDICATOR_DATA_NOT_FOUND/ 4806/ Requested data not found

Have you tried a while?

while(CopyBuffer(i_handle,0,0,6,i_buffer)==-1)
   {
      Sleep(100);
   }
Alain Verleyen
Moderator
33799
Alain Verleyen  
Henrique Vilela:

Have you tried a while?

No a good idea to use Sleep() in OnInit. And you are risking an endless loop.
Alain Verleyen
Moderator
33799
Alain Verleyen  
Marcelo Coutinho:
ERR_INDICATOR_DATA_NOT_FOUND/ 4806/ Requested data not found

Your indicator is not yet ready.

Seems a lot of Brazilian people are trying to use CopyBuffer() in OnInit().

Henrique Vilela
1713
Henrique Vilela  
Alain Verleyen:
No a good idea to use Sleep() in OnInit. And you are risking an endless loop.

Sorry, of course it's supposed to add a counter to avoid an endless loop. (Coutinho is an experienced programmer, he would realize that).

My point is that the problem may not be that the data is not available at all, but just not available yet and a loop will solve that.

PS: Never tried and CopyBuffer in OnInit, it's just and idea.

Marcelo Coutinho
1205
Marcelo Coutinho  
Alain Verleyen:

Your indicator is not yet ready.

Seems a lot of Brazilian people are trying to use CopyBuffer() in OnInit().

So ... please, what do you suggest in order to verify if my buffers are ready before OnTick() ?
Alain Verleyen
Moderator
33799
Alain Verleyen  
Marcelo Coutinho:
So ... please, what do you suggest in order to verify if my buffers are ready before OnTick() ?
Why ? What are you trying to solve ?
12
To add comments, please log in or register