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
191
Peter Schnuerer 2012.07.04 21:15 

Hi, 

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
   SetIndexBuffer(0,ExtMacdBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
   SetIndexBuffer(2,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);

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
191
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);

into

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

To add comments, please log in or register