Download MetaTrader 5

GetData returns "invalid buffer" from MACD Indicator

To add comments, please log in or register
Sell products right in MetaTrader. Millions of traders are waiting for this!
Peter Schnuerer
Peter Schnuerer 2012.07.04 21:15 


Im working on my frist Expert , based in the CExpertSignal.

Im trying to access data from the MACD Indocator, that is located in  "Examples\\MACD.ex5".

The OnInit() method of MACD.mq5 in "Indicators\\Examples" says:

//--- indicator buffers mapping

Therefore I would expext to access data of the ExtMacdBuffer und ExtSignalBuffer as follows.

   double            MACDLine(const int index)             const { return(m_MACD.GetData(0, index)); }
   double            MACDSignal(const int index)           const { return(m_MACD.GetData(1,index)); }


   //--- For operation with ticks idx=0, for operation with formed bars idx=1
   int idx=StartIndex();

   //--- Values of MAs at the last formed bar
   double last_MACD_value=MACDLine(idx);
   double last_MACDSignal_value=MACDSignal(idx);


But access works only for the first Buffer (ExtMacdBuffer) while any attempt to access the second Buffer (ExtSignalBuffer) throws a "CIndicator::GetData: invalid buffer" error.

Any suggestions?

Thanks, Peter

Peter Schnuerer
Peter Schnuerer 2012.07.05 23:59  

OK - I found it:

Aftrer creation of the MACD-Indicator, I just needed to change

   //--- Number of buffers
   if(!m_MACD.NumBuffers(1)) return(false);


   //--- Number of buffers
   if(!m_MACD.NumBuffers(2)) return(false); 

To add comments, please log in or register