problems with CopyBuffer in strategy tester

 

Hopefully I am not missing anything obvious but for some reason the if block that I have in bold below is returning lots of error 4806 errors in strategy tester:

Does anyone have any ideas what I'm doing wrong or why this kind of thing won't work in the strategy tester?

 thanks 

================= 

        //--- Get the handles for Moving Average indicators
         fastestMA_hdl = iMA(recommendedPair, EMAtimeFrame, EMA1, 0, MODE_EMA, PRICE_CLOSE);
         fastMA_hdl = iMA(recommendedPair, EMAtimeFrame, EMA2, 0, MODE_EMA, PRICE_CLOSE);
         mediumMA_hdl = iMA(recommendedPair, EMAtimeFrame, EMA3, 0, MODE_EMA, PRICE_CLOSE);
         slowMA_hdl = iMA(recommendedPair, EMAtimeFrame, EMA4, 0, MODE_EMA, PRICE_CLOSE);

         //--- What if handle returns Invalid Handle
         if (fastestMA_hdl < 0 || fastMA_hdl < 0 || mediumMA_hdl < 0 || slowMA_hdl < 0)
         {
            Alert("Error Creating Handle(s) for Moving Avg. indicator!!");
            Print("Error Creating Handle(s) for Moving Avg. indicator!!");
            IndicatorRelease(fastestMA_hdl);
            IndicatorRelease(fastMA_hdl);
            IndicatorRelease(mediumMA_hdl);
            IndicatorRelease(slowMA_hdl);
            return;
         } 

         // get EMA for specified periods on specified time frame using best currency pair
         // fastest
         if(CopyBuffer(fastestMA_hdl,0,0,1,fastestMA)<0)
         {
            Alert("Error copying fastest Moving Average indicator buffer - error:",GetLastError());
            Print("Error copying fastest Moving Average indicator buffer - error:",GetLastError());
            IndicatorRelease(fastestMA_hdl);
            IndicatorRelease(fastMA_hdl);
            IndicatorRelease(mediumMA_hdl);
            IndicatorRelease(slowMA_hdl);
            return;
         }  
         // fast
         if(CopyBuffer(fastMA_hdl,0,0,1,fastMA)<0)
         {
            Alert("Error copying fast Moving Average indicator buffer - error:",GetLastError());
            Print("Error copying fast Moving Average indicator buffer - error:",GetLastError());
            IndicatorRelease(fastestMA_hdl);
            IndicatorRelease(fastMA_hdl);
            IndicatorRelease(mediumMA_hdl);
            IndicatorRelease(slowMA_hdl);
            return;
         }  
        
         // medium
         if(CopyBuffer(mediumMA_hdl,0,0,1,mediumMA)<0)
         {
            Alert("Error copying medium Moving Average indicator buffer - error:",GetLastError());
            Print("Error copying medium Moving Average indicator buffer - error:",GetLastError());
            IndicatorRelease(fastestMA_hdl);
            IndicatorRelease(fastMA_hdl);
            IndicatorRelease(mediumMA_hdl);
            IndicatorRelease(slowMA_hdl);
            return;
         }  
        
         // slow
         if(CopyBuffer(slowMA_hdl,0,0,1,slowMA)<0)
         {
            Alert("Error copying slow Moving Average indicator buffer - error:",GetLastError());
            Print("Error copying slow Moving Average indicator buffer - error:",GetLastError());
            IndicatorRelease(fastestMA_hdl);
            IndicatorRelease(fastMA_hdl);
            IndicatorRelease(mediumMA_hdl);
            IndicatorRelease(slowMA_hdl);
            return;
         }  

Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Indicators Lines - Documentation on MQL5
 
milfordT:

Hopefully I am not missing anything obvious but for some reason the if block that I have in bold below is returning lots of error 4806 errors in strategy tester:

Does anyone have any ideas what I'm doing wrong or why this kind of thing won't work in the strategy tester?

 thanks 

================= 

        //--- Get the handles for Moving Average indicators
         fastestMA_hdl = iMA(recommendedPair, EMAtimeFrame, EMA1, 0, MODE_EMA, PRICE_CLOSE);
         fastMA_hdl = iMA(recommendedPair, EMAtimeFrame, EMA2, 0, MODE_EMA, PRICE_CLOSE);
         mediumMA_hdl = iMA(recommendedPair, EMAtimeFrame, EMA3, 0, MODE_EMA, PRICE_CLOSE);
         slowMA_hdl = iMA(recommendedPair, EMAtimeFrame, EMA4, 0, MODE_EMA, PRICE_CLOSE);

         //--- What if handle returns Invalid Handle
         if (fastestMA_hdl < 0 || fastMA_hdl < 0 || mediumMA_hdl < 0 || slowMA_hdl < 0)
         {
            Alert("Error Creating Handle(s) for Moving Avg. indicator!!");
            Print("Error Creating Handle(s) for Moving Avg. indicator!!");
            IndicatorRelease(fastestMA_hdl);
            IndicatorRelease(fastMA_hdl);
            IndicatorRelease(mediumMA_hdl);
            IndicatorRelease(slowMA_hdl);
            return;
         } 

         // get EMA for specified periods on specified time frame using best currency pair
         // fastest
         if(CopyBuffer(fastestMA_hdl,0,0,1,fastestMA)<0)
         {
            Alert("Error copying fastest Moving Average indicator buffer - error:",GetLastError());
            Print("Error copying fastest Moving Average indicator buffer - error:",GetLastError());
            IndicatorRelease(fastestMA_hdl);
            IndicatorRelease(fastMA_hdl);
            IndicatorRelease(mediumMA_hdl);
            IndicatorRelease(slowMA_hdl);
            return;
         }  
         // fast
         if(CopyBuffer(fastMA_hdl,0,0,1,fastMA)<0)
         {
            Alert("Error copying fast Moving Average indicator buffer - error:",GetLastError());
            Print("Error copying fast Moving Average indicator buffer - error:",GetLastError());
            IndicatorRelease(fastestMA_hdl);
            IndicatorRelease(fastMA_hdl);
            IndicatorRelease(mediumMA_hdl);
            IndicatorRelease(slowMA_hdl);
            return;
         }  
        
         // medium
         if(CopyBuffer(mediumMA_hdl,0,0,1,mediumMA)<0)
         {
            Alert("Error copying medium Moving Average indicator buffer - error:",GetLastError());
            Print("Error copying medium Moving Average indicator buffer - error:",GetLastError());
            IndicatorRelease(fastestMA_hdl);
            IndicatorRelease(fastMA_hdl);
            IndicatorRelease(mediumMA_hdl);
            IndicatorRelease(slowMA_hdl);
            return;
         }  
        
         // slow
         if(CopyBuffer(slowMA_hdl,0,0,1,slowMA)<0)
         {
            Alert("Error copying slow Moving Average indicator buffer - error:",GetLastError());
            Print("Error copying slow Moving Average indicator buffer - error:",GetLastError());
            IndicatorRelease(fastestMA_hdl);
            IndicatorRelease(fastMA_hdl);
            IndicatorRelease(mediumMA_hdl);
            IndicatorRelease(slowMA_hdl);
            return;
         }  

 

As a general comment...

1)Is this block of code from the EA's Init block? If not I think the handles at least should be declared in the init block.

2)You may want to use the standard library buffers like CiMA and CiDEMA  

These are pretty straight forward and all you have to do is refresh each instance of their respective class, before calling them and also resizing the buffer at the end of the init block on creation. 

 

 

 

 
ssn:

As a general comment...

1)Is this block of code from the EA's Init block? If not I think the handles at least should be declared in the init block.

2)You may want to use the standard library buffers like CiMA and CiDEMA  

These are pretty straight forward and all you have to do is refresh each instance of their respective class, before calling them and also resizing the buffer at the end of the init block on creation. 

 

 

 

this is from OnTick().   There is code preceding what I have posted that determines what the currency pair parameter will be (it can change from one tick to the next) so it can't go in init(). 

 

 

I think, before you try to get any data from the handle, you should check whether the data you're trying to get is already calculated. You can use the BarsCalculated() function to perform this check.

 
alexvd:

I think, before you try to get any data from the handle, you should check whether the data you're trying to get is already calculated. You can use the BarsCalculated() function to perform this check.

Thankyou for the tip.  I needed some retry logic in places but unfortunately the strategy tester still cannot handle my EA as I eventually get the same erros plus others.  Here is a portion of the log file from my last run.  Seem to be getting a lot of MemoryException errors now:

 KP 3 MemoryException 08:32:49 65536 bytes not available
II 3 MemoryException 08:32:49 65536 bytes not available
GF 3 MemoryException 08:32:49 65536 bytes not available
EO 3 MemoryException 08:32:49 65536 bytes not available
CD 3 MemoryException 08:32:49 65536 bytes not available
QL 3 MemoryException 08:32:49 65536 bytes not available
OE 3 MemoryException 08:32:49 65536 bytes not available
MR 3 MemoryException 08:32:49 65536 bytes not available
KK 3 MemoryException 08:32:49 65536 bytes not available
IP 3 MemoryException 08:32:49 65536 bytes not available
GI 3 MemoryException 08:32:49 65536 bytes not available
EF 3 MemoryException 08:32:49 65536 bytes not available
CO 3 MemoryException 08:32:49 65536 bytes not available
QG 3 MemoryException 08:32:49 65536 bytes not available
OL 3 MemoryException 08:32:49 65536 bytes not available
ME 3 MemoryException 08:32:49 65536 bytes not available
KR 3 MemoryException 08:32:49 65536 bytes not available
IK 3 MemoryException 08:32:49 65536 bytes not available
KR 0 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:07   Alert: Error copying fast Moving Average indicator buffer - error:4806
OL 0 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:07   Error copying fast Moving Average indicator buffer - error:4806
ES 3 MemoryException 08:32:49 65536 bytes not available
CH 3 MemoryException 08:32:49 65536 bytes not available
QP 3 MemoryException 08:32:49 65536 bytes not available
OI 3 MemoryException 08:32:49 65536 bytes not available
MF 3 MemoryException 08:32:49 65536 bytes not available
KO 3 MemoryException 08:32:49 65536 bytes not available
ID 3 MemoryException 08:32:49 65536 bytes not available
GM 3 MemoryException 08:32:49 65536 bytes not available
EJ 3 MemoryException 08:32:49 65536 bytes not available
CS 3 MemoryException 08:32:49 65536 bytes not available
QK 3 MemoryException 08:32:49 65536 bytes not available
OP 3 MemoryException 08:32:49 65536 bytes not available
MI 3 MemoryException 08:32:49 65536 bytes not available
KF 3 MemoryException 08:32:49 65536 bytes not available
IO 3 MemoryException 08:32:49 65536 bytes not available
GD 3 MemoryException 08:32:49 65536 bytes not available
EM 3 MemoryException 08:32:49 65536 bytes not available
CJ 3 MemoryException 08:32:49 65536 bytes not available
QR 3 MemoryException 08:32:49 65536 bytes not available
OK 3 MemoryException 08:32:49 65536 bytes not available
CL 0 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:12   Alert: Error copying fastest Moving Average indicator buffer - error:4806
MR 0 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:12   Error copying fastest Moving Average indicator buffer - error:4806
OR 3 MemoryException 08:32:49 65536 bytes not available
MK 3 MemoryException 08:32:49 65536 bytes not available
KP 3 MemoryException 08:32:49 65536 bytes not available
II 3 MemoryException 08:32:49 65536 bytes not available
GF 3 MemoryException 08:32:49 65536 bytes not available
EO 3 MemoryException 08:32:49 65536 bytes not available
CD 3 MemoryException 08:32:49 65536 bytes not available
QL 3 MemoryException 08:32:49 65536 bytes not available
OE 3 MemoryException 08:32:49 65536 bytes not available
MR 3 MemoryException 08:32:49 65536 bytes not available
KK 3 MemoryException 08:32:49 65536 bytes not available
IP 3 MemoryException 08:32:49 65536 bytes not available
GI 3 MemoryException 08:32:49 65536 bytes not available
EF 3 MemoryException 08:32:49 65536 bytes not available
CO 3 MemoryException 08:32:49 65536 bytes not available
QG 3 MemoryException 08:32:49 65536 bytes not available
OL 3 MemoryException 08:32:49 65536 bytes not available
ME 3 MemoryException 08:32:49 65536 bytes not available
KR 3 MemoryException 08:32:49 65536 bytes not available
IK 3 MemoryException 08:32:49 65536 bytes not available
NL 0 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:17   Alert: Error copying fastest Moving Average indicator buffer - error:4806
HS 0 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:17   Error copying fastest Moving Average indicator buffer - error:4806
IR 3 MemoryException 08:32:49 65536 bytes not available
GK 3 MemoryException 08:32:49 65536 bytes not available
EP 3 MemoryException 08:32:49 65536 bytes not available
CI 3 MemoryException 08:32:49 65536 bytes not available
QQ 3 MemoryException 08:32:49 65536 bytes not available
ON 3 MemoryException 08:32:49 65536 bytes not available
MG 3 MemoryException 08:32:49 65536 bytes not available
KL 3 MemoryException 08:32:49 65536 bytes not available
IE 3 MemoryException 08:32:49 65536 bytes not available
GR 3 MemoryException 08:32:49 65536 bytes not available
EK 3 MemoryException 08:32:49 65536 bytes not available
CP 3 MemoryException 08:32:49 65536 bytes not available
QH 3 MemoryException 08:32:49 65536 bytes not available
OQ 3 MemoryException 08:32:49 65536 bytes not available
MN 3 MemoryException 08:32:49 65536 bytes not available
KG 3 MemoryException 08:32:49 65536 bytes not available
IL 3 MemoryException 08:32:49 65536 bytes not available
GE 3 MemoryException 08:32:49 65536 bytes not available
ER 3 MemoryException 08:32:49 65536 bytes not available
CK 3 MemoryException 08:32:49 65536 bytes not available
JO 0 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:22   Alert: Error copying fastest Moving Average indicator buffer - error:4806
HS 0 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:22   Error copying fastest Moving Average indicator buffer - error:4806
CR 3 MemoryException 08:32:49 85248 bytes not available
DI 2 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:22   expert removed because indicator 'Moving Average' cannot load [4805]
EJ 3 MemoryException 08:32:49 85248 bytes not available
RP 2 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:22   expert removed because indicator 'Moving Average' cannot load [4805]
GR 3 MemoryException 08:32:49 85248 bytes not available
PH 2 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:22   expert removed because indicator 'Moving Average' cannot load [4805]
IJ 3 MemoryException 08:32:49 85248 bytes not available
NP 2 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:22   expert removed because indicator 'Moving Average' cannot load [4805]
KN 0 11901_20110524 (EURUSD,M30) 08:32:49 2011.04.25 06:33:22   Error Creating Handle(s) for Moving Avg. indicator!!
OS 3 MemoryException 08:32:49 65536 bytes not available
DH 0 Tester 08:32:49 OnTester result 0
ME 3 Tester 08:32:49 expert self removed on 27% of testing interval
RN 0 Tester 08:32:49 EURUSD,M30: 16298 ticks (14 bars) generated within 79841 ms (total bars in history 16208, total time 82415 ms)
MO 0 Tester 08:32:49 log file "C:\Users\OSR2\AppData\Roaming\MetaQuotes\Tester\D0E8209F77C8CF37AD8BF550E51FF075\Agent-127.0.0.1-3000\logs\20110524.log" written
LI 2 Tester 08:32:49 pumping of orders history failed
LN 2 Tester 08:32:49 pumping of deals history failed
KD 0 Tester 08:32:49 tester agent shutdown
HH 0 Server 08:38:17 MetaTester 5 stopped

 

Memory exceptions mean that you don't have enough free memory or the memory is fragmented.

Try to restart terminal, close all charts which aren't used and decrease period of testing.

 
Alternatively if your currency pairs are not that many, you could create a handle for each pair in Init and then simply call the appropriate buffer on tick.
 
alexvd:

Memory exceptions mean that you don't have enough free memory or the memory is fragmented.

Try to restart terminal, close all charts which aren't used and decrease period of testing.

I am only testing over 1 days worth of history.  I am also now restarting terminal between every run. 

I did a little experimenting and changed the EA to only run on every other tick.  Doint this I was able to eliminate the memory exceptions.  However the EA still cannot run to completion in strategy tester and I am now getting the following errors logged:

CP 2 11901_20110525 (EURUSD,M30) 08:39:15 2011.04.25 07:13:30   expert removed because indicator 'Moving Average' cannot load [4801]
GQ 2 11901_20110525 (EURUSD,M30) 08:39:15 2011.04.25 07:13:30   expert removed because indicator 'Moving Average' cannot load [4801]
KQ 2 11901_20110525 (EURUSD,M30) 08:39:15 2011.04.25 07:13:30   expert removed because indicator 'Moving Average' cannot load [4801]
ON 2 11901_20110525 (EURUSD,M30) 08:39:15 2011.04.25 07:13:30   expert removed because indicator 'Moving Average' cannot load [4801]
NP 0 11901_20110525 (EURUSD,M30) 08:39:15 2011.04.25 07:13:30   Error Creating Handle(s) for Moving Avg. indicator!!
HM 0 Tester 08:39:15 OnTester result 0
KJ 3 Tester 08:39:15 expert self removed on 30% of testing interval
IQ 0 Tester 08:39:15 EURUSD,M30: 17803 ticks (15 bars) generated within 69389 ms (total bars in history 16209, total time 71604 ms)
JR 0 Tester 08:39:15 log file "C:\Users\OSR2\AppData\Roaming\MetaQuotes\Tester\D0E8209F77C8CF37AD8BF550E51FF075\Agent-127.0.0.1-3000\logs\20110525.log" written
IS 0 Tester 08:39:15 tester agent shutdown
 

 

Anyone have a clue on this?  EA works realtime but always has these errors (see previous post) in strategy tester.

 
milfordT:

I am only testing over 1 days worth of history.  I am also now restarting terminal between every run. 

I did a little experimenting and changed the EA to only run on every other tick.  Doint this I was able to eliminate the memory exceptions.  However the EA still cannot run to completion in strategy tester and I am now getting the following errors logged:

CP 2 11901_20110525 (EURUSD,M30) 08:39:15 2011.04.25 07:13:30   expert removed because indicator 'Moving Average' cannot load [4801]
GQ 2 11901_20110525 (EURUSD,M30) 08:39:15 2011.04.25 07:13:30   expert removed because indicator 'Moving Average' cannot load [4801]
KQ 2 11901_20110525 (EURUSD,M30) 08:39:15 2011.04.25 07:13:30   expert removed because indicator 'Moving Average' cannot load [4801]
ON 2 11901_20110525 (EURUSD,M30) 08:39:15 2011.04.25 07:13:30   expert removed because indicator 'Moving Average' cannot load [4801]
NP 0 11901_20110525 (EURUSD,M30) 08:39:15 2011.04.25 07:13:30   Error Creating Handle(s) for Moving Avg. indicator!!
HM 0 Tester 08:39:15 OnTester result 0
KJ 3 Tester 08:39:15 expert self removed on 30% of testing interval
IQ 0 Tester 08:39:15 EURUSD,M30: 17803 ticks (15 bars) generated within 69389 ms (total bars in history 16209, total time 71604 ms)
JR 0 Tester 08:39:15 log file "C:\Users\OSR2\AppData\Roaming\MetaQuotes\Tester\D0E8209F77C8CF37AD8BF550E51FF075\Agent-127.0.0.1-3000\logs\20110525.log" written
IS 0 Tester 08:39:15 tester agent shutdown
 

You better write a ticket to ServiceDesk. Please attach: source code of your EA, strategy tester settings, full logs of tester and tester agent.

 
alexvd:

You better write a ticket to ServiceDesk. Please attach: source code of your EA, strategy tester settings, full logs of tester and tester agent.

Hello,

i had a problem with error 4806 and "...bytes not available" too. My EA was running over several month and than suddenly stopped working.

After long time of searching, I realized by coincidence that my EA runs with an old version of MetaTrader (build 353 from November 2010), but not with the actual build 458.

Maybe it is the same with your EA.

Reason: