CopyBuffer does not work in OnInit() function ?

 

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

 
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 ?
 
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

 
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 ?

 
Alain Verleyen:

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

ERR_INDICATOR_DATA_NOT_FOUND/ 4806/ Requested data not found
 
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);
   }
 
Henrique Vilela:

Have you tried a while?

No a good idea to use Sleep() in OnInit. And you are risking an endless loop.
 
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().

 
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.

 
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() ?
 
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 ?
Reason: