Erreur en utilisant plusieurs indicateurs techniques en même temps

 
Bonjour
Ce "custom indicator" devait dessiner 2 moyennes mobiles simple de périodes 7 et 20
#property indicator_chart_window
#property indicator_buffers 2 
#property indicator_plots   2
#property indicator_label1  "iMA1" 
#property indicator_type1   DRAW_LINE 
#property indicator_color1  clrWhite 
#property indicator_style1  STYLE_SOLID 
#property indicator_width1  1 
#property indicator_label2  "iMA2" 
#property indicator_type2   DRAW_LINE 
#property indicator_color2  clrRed 
#property indicator_style2  STYLE_SOLID 
#property indicator_width2  1 
//
input int ma_period1=7, ma_period2=20;
double  iMABuffer1[], iMABuffer2[]; 
int handle1, handle2, index1=0, index2=1; 
//
int OnInit(){
   SetIndexBuffer(index1, iMABuffer1, INDICATOR_DATA); 
   PlotIndexSetInteger(index1, PLOT_SHIFT, 0); 
   handle1 = iMA(NULL, 0, ma_period1, 0, MODE_SMA, PRICE_CLOSE);  
   if(handle1 == INVALID_HANDLE) return(INIT_FAILED); 
   
   SetIndexBuffer(index2, iMABuffer2, INDICATOR_DATA); 
   PlotIndexSetInteger(index2, PLOT_SHIFT, 0); 
   handle2 = iMA(NULL, 0, ma_period2, 0, MODE_SMA, PRICE_CLOSE);  
   if(handle2 == INVALID_HANDLE) return(INIT_FAILED); 
   return(INIT_SUCCEEDED);
}
//
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[]){
   int x, y, errx, erry;
   ResetLastError();
   x = CopyBuffer(handle1, index1, 0, 25, iMABuffer1);
   errx = GetLastError();  
   ResetLastError(); 
   y = CopyBuffer(handle2, index2, 0, 25, iMABuffer2);
   erry = GetLastError();
   Comment(x + " " + errx + " " + y + " " + erry);
   if (x<0 || y<0) return(0);
   return(rates_total);
} 
//  
void OnDeinit(const int reason) { 
   if(handle1 != INVALID_HANDLE) IndicatorRelease(handle1); 
   if(handle2 != INVALID_HANDLE) IndicatorRelease(handle2); 
   Comment("");
}     


Le prmeier appel à "CopyBuffer" passe sans erreur.

Mais la deuxième exécution de "CopyBuffer" renvoit -1.
Et le code de l'erreur est 4806 (ERR_INDICATOR_DATA_NOT_FOUND : Requested data not found)

Comment résoudre


 
résolu le pb : il faut index1 = index2 = 0 (même indicator buffer value)
Raison: