Problem with copy buffer

 

Hi Guys , 


I'm having a problem with CopyBuffer(). As soon as I change the input parameter indicator buffer from 0 to 1 no data is shown on the chart. Does anybody know what's going on ? The reference guide is not helpful at all.


Thank you very much indeed.

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,emaBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,emaBuffer2,INDICATOR_DATA);
   
   ema_handle = iMA(NULL,PERIOD_CURRENT,ema_period,0,MODE_EMA,PRICE_CLOSE);
   ema_handle2 = iMA(NULL,PERIOD_CURRENT,ema_period2,0,MODE_EMA,PRICE_CLOSE);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   CopyBuffer(ema_handle,0,0,rates_total,emaBuffer);
   CopyBuffer(ema_handle2,1,0,rates_total,emaBuffer2);
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 

The iMA indicator has only one indicator buffer.

Your code contains an error:

   CopyBuffer(ema_handle,0,0,rates_total,emaBuffer);
   CopyBuffer(ema_handle2,1,0,rates_total,emaBuffer2);

it is correct to write like this:

   CopyBuffer(ema_handle,0,0,rates_total,emaBuffer);
   CopyBuffer(ema_handle2,0,0,rates_total,emaBuffer2);
 

Hi Vladimir, 


Yes I fixed a minute ago. 


CopyBuffer( ind_handle , indexbuffernumber , start pos , array[] ). I thought that index buffer number was referring to number set via SetIndexBuffer(). The ref guide is misleading sometimes. 

In this case is the number of iMa buffer which is only 1. 


Thank you very much indeed

 
claudio.zeccolella: I thought that index buffer number was referring to number set via SetIndexBuffer(). 

It is — of the indicator you are reading. Moving Average only has one buffer (index zero).