error copying 4806

samjesse

Active Trader
Aug 30, 2011
118
0
27
Hi

I do not know if I am doing something wrong here for that error to appear.
the error only appears on the s_Ma buffer "last line"

MQL5:
            int x = Bars(pair.names[i], pair.periods[j]);  //-- x --- amount of bars to process ------
            int y = x-slow_iMa;                            //-- y --- amount of usable bars ---------- 
            // ... some other code here
            int f_iMa_Handle = iMA(pair.names[i], pair.periods[j],fast_iMa,0,MODE_SMA,PRICE_CLOSE);      
            int s_iMa_Handle = iMA(pair.names[i], pair.periods[j],slow_iMa,0,MODE_SMA,PRICE_CLOSE);
            if(CopyBuffer(f_iMa_Handle, 0, 0, y, f_Ma)<=0) Print("Error copying fast Ma ",GetLastError());
            if(CopyBuffer(s_iMa_Handle, 1, 0, y, s_Ma)<=0) Print("Error copying slow Ma ",GetLastError());
 
Last edited by a moderator:

samjesse

Active Trader
Aug 30, 2011
118
0
27
If I switch the order of the last 2 lines, the last code line will produce the error copying 4806.
 

Enivid

Administrator
Staff member
Nov 30, 2008
16,039
817
144
Odessa
www.earnforex.com
It takes some time for MetaTrader to produce the indicator data, so it's possible that the second indicator isn't ready when you call CopyBuffer(). Try to catch that error and re-do copying until it disappears.
 

samjesse

Active Trader
Aug 30, 2011
118
0
27
It takes some time for MetaTrader to produce

so the code that needs to be repeated would be the code that has to do with producing the indicator? i.e.
MQL5:
int s_iMa_Handle = iMA(pair.names[i], pair.periods[j],slow_iMa,0,MODE_SMA,PRICE_CLOSE);


re-do copying until it disappears.
you mean this code?
MQL5:
if(CopyBuffer(s_iMa_Handle, 1, 0, y, s_Ma)<=0) Print("Error copying slow Ma ",GetLastError());

why redo the copy if the problem in the "produce" code that takes time?
 
Last edited by a moderator:

Enivid

Administrator
Staff member
Nov 30, 2008
16,039
817
144
Odessa
www.earnforex.com
When you call iMA(), it takes some time for MetaTrader to calculate all the data. Until it's done, the handle doesn't point at the correct data.

There is no point in calling iMA() more than one time, as it will probably trigger MetaTrader to restart indicator calculation.

The point is to call CopyBuffer() in a cycle until it stops returning an error.
 

samjesse

Active Trader
Aug 30, 2011
118
0
27
is the following OK. if loops for a long time and I stop it manually.

MQL5:
           int f_iMa_Handle = iMA(nm, tf,fast_iMa,0,MODE_SMA,PRICE_CLOSE);      
            while(CopyBuffer(f_iMa_Handle, 0, 0, y, f_Ma)<=0) Print("Error copying fast Ma ",GetLastError());
            int s_iMa_Handle = iMA(nm, tf,slow_iMa,0,MODE_SMA,PRICE_CLOSE);
            while(CopyBuffer(s_iMa_Handle, 1, 0, y, s_Ma)<=0) Print("Error copying slow Ma ",GetLastError());
 
Last edited by a moderator: