CopyBuffer error MQL5

 

Hi, 

I have coded a multi symbol mql5 ea which compiles fine but when I run it through the strategy tester there seems to be an issue with the CopyBuffer function. Just by looking does anyone know why this might be? 

//Checking and Copying Indicator Values
if(CopyBuffer(MACD_Handle[i],0,1,4,MACD_MainLine))
  {
   Print("Error Copying Indicator Data",GetLastError());
   return;
  }
if(CopyBuffer(MACD_Handle[i],1,1,4, MACD_Signal))
  {
   Print("Error Copying Indicator Data",GetLastError());
   return;
  }
Thanks
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
  • www.mql5.com
CopyBuffer - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Mr David Mcbride:

Hi, 

I have coded a multi symbol mql5 ea which compiles fine but when I run it through the strategy tester there seems to be an issue with the CopyBuffer function. Just by looking does anyone know why this might be? 

//Checking and Copying Indicator Values
if(CopyBuffer(MACD_Handle[i],0,1,4,MACD_MainLine))
  {
   Print("Error Copying Indicator Data",GetLastError());
   return;
  }
if(CopyBuffer(MACD_Handle[i],1,1,4, MACD_Signal))
  {
   Print("Error Copying Indicator Data",GetLastError());
   return;
  }

Thanks

If return is equal to -1, then print errors
 
_MAHA_ #:
If return is equal to -1, then print errors

Hi; 

it prints the error when backtesting. It wont open any trades as there is an issue copying the indicator values.

 
Mr David Mcbride #:

Hi; 

it prints the error when backtesting. It wont open any trades as there is an issue copying the indicator values.

if(CopyBuffer(MACD_Handle[i],0,1,4,MACD_MainLine)==-1)
        {
         Print("Error Copying Indicator Data",GetLastError());
         return;
        }
      if(CopyBuffer(MACD_Handle[i],1,1,4, MACD_Signal)==-1)
        {
         Print("Error Copying Indicator Data",GetLastError());
         return;
        }

If you still get an error, paste the entire code and log.

 

@Mr David Mcbride, please edit your previous post and use the "</>" icon or Alt-S to post your code, or attach it as a file with .

Don't just copy/paste it in plain text because it is difficult to read.

 
Mr David Mcbride:

Hi, 

I have coded a multi symbol mql5 ea which compiles fine but when I run it through the strategy tester there seems to be an issue with the CopyBuffer function. Just by looking does anyone know why this might be? 

//Checking and Copying Indicator Values
if(CopyBuffer(MACD_Handle[i],0,1,4,MACD_MainLine))
  {
   Print("Error Copying Indicator Data",GetLastError());
   return;
  }
if(CopyBuffer(MACD_Handle[i],1,1,4, MACD_Signal))
  {
   Print("Error Copying Indicator Data",GetLastError());
   return;
  }

Thanks

If(CopyBuffer…..) means nothing… CopyBuffer is an int function therefore you have to write if(CopyBuffer(…..) < 1) error else it’s ok.

Your CopyBuffer works but compiler goes into { } where prints error 🙄
Reason: