Anyone with a Light in my Darkness of CopyBuffer?

 

I just want to see a simple ema:

  1. In OnInit() I create the handle and defined 3 buffers successfully!!
  2. In OnCalculate() I want to copy the values into the buffer:
   int limit=rates_total-prev_calculated;
   int count=(limit>1 ? rates_total : 1), copied=0;
   copied = CopyBuffer(Hdl_Ema,1,0,count,Buff01);
   if(copied!=count) { Print(ErrInf("CopyBuffer failed"),"\ncount ",count,"  copied: ",copied,"  BarsCalc: ",BarsCalculated(Hdl_Ema)); ChartIndicatorDelete(0,0,IndiShortName); } //Line 145
...
   Print("iB ",iB,"  iLast ",iLast,"   rates_total ",rates_total,"   prev_calculated ",prev_calculated,"  time[",iLast,"] ",time[iLast],"  time[",iB,"] ",time[iB]);
   // now iB == iLast == actual Bar
   Buff02[iB] =  ema(     close[iB], Buff02[iB-1]==0 ? close[iB-1] : Buff02[iB-1], CEma ); // line 153
   Buff03[iB] =  emaCalc( close[iB], Buff03[iB-1]==0 ? close[iB-1] : Buff03[iB-1], CEma ); // line 154:  buffer02 was defined in OnInit() like the other two
   return(rates_total);


And this is what I get in the expert tab (log):

End of OnInit() tC 13:38:30 tL 12:38:30.0062 Idx: 3  ok: true
Err[4806] ERR_INDICATOR_DATA_NOT_FOUND: Requested data not found CopyBuffer failed tC 13:38:30 tL 12:38:30.0109
count 1469521  copied: -1  BarsCalc: 1469521
iB 5  iLast 1469520   rates_total 1469521   prev_calculated 0  time[1469520] 2018.10.08 13:35:00  time[5] 1971.01.11 00:00:00
array out of range in 'TriEmaTest.mq5' (154,45)
  1. BarsCalculated() == 1469521 but nothing is copied because err 4806: Indicator data not found ???
  2. I call ChartIndicatorDelete(..) and the indicator disappeared from the chart but why it executes OnCalculate() until the last line?
  3. Three buffers were defined in the same way in OnInit() - why does buffer03 has a aray size problem - the others don't??
 

Are you checking to ensure that the handles are valid before calling CopyBuffer? Also, have you considered using the standard library classes for managing your simple indicators? I ask because it will do all of the buffer updating for you. It's as easy as...


#include <Indicators\Indicators.mqh>

CIndicators    indicators;
CiMA           ema1, ema2, ema3;

int OnInit()
{
   if(
         !ema1.Create(_Symbol, _Period, 20, 0, MODE_EMA, PRICE_CLOSE)
      || !ema2.Create(_Symbol, _Period, 50, 0, MODE_EMA, PRICE_CLOSE)
      || !ema3.Create(_Symbol, _Period, 200, 0, MODE_EMA, PRICE_CLOSE)
      || !indicators.Add(&ema1)
      || !indicators.Add(&ema2)
      || !indicators.Add(&ema3)
   ){
      return INIT_FAILED;
   }
   return INIT_SUCCEEDED;
}

void OnTick()
{ 
   indicators.Refresh(); //refresh indicator buffers
}
 

I create only one iMA-call successfully:

   Hdl_Ema = iMA(_Symbol,PERIOD_CURRENT,PEma,0,MODE_EMA, PRICE_CLOSE);
   if(Hdl_Ema==INVALID_HANDLE) {
      Print(__LINE__," The iMA(",(string)Hdl_Ema,") by PEma: ",PEma," prc: ",EnumToString(PRICE_CLOSE)," object was not created: Error ",GetLastError());
      return INIT_FAILED;
   }
The other two I want to calc. myself in different ways..
 
Carl Schreiber:

I create only one iMA-call successfully:

The other two I want to calc. myself in different ways..

Oh... I see your issue... you're calling the wrong buffer index

copied = CopyBuffer(Hdl_Ema,1,0,count,Buff01);

Should be index 0. ;)

 

Thank you it was exactly that. I copied the structure from another indicator and was trapped by "Indicator data not found" which I thought points to missing data from the server.