iMAOnArray некорректная работа функции на НЕ отображаемых массивах

 
Столкнулся с некорректной работой функции iMAOnArray на не отображаемых массивах
Для описания бага был написан демонстрационный индикатор и советник.
Привожу код индикатора
#property copyright "nigilist"
#property link      "nigilist_t@mail.ru"
//установки окна индикатора---------
#property indicator_chart_window
#property indicator_buffers 8
//----------------------------------
//предустановки линий------------------------------
#property indicator_color1 Red        
#property indicator_width1 1
#property indicator_style1 1
#property indicator_color2 Blue        
#property indicator_width2 1
#property indicator_style2 1 
#property indicator_color3 CornflowerBlue     
#property indicator_width3 3
#property indicator_style3 1
//-------------------------------------------------
//внутрение переменные-----------------------------
int cnt, limit;
//буфферы------------------------------------------
double line1[], line2[], line3[500000], line4[];
//-------------------------------------------------
 
int init()
{
//линии индикатора---------------------------------
 SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, line1);
 SetIndexLabel(0, "resistance");
      
 SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1, line2);
 SetIndexLabel(1, "support");
 
 SetIndexStyle(2, DRAW_LINE);
SetIndexBuffer(2, line4);
//------------------------------------------------
//изменение индексации в сформированных массивах--
ArraySetAsSeries(line3,true);
//------------------------------------------------
}
 
int start()
{
 int counted_bars=IndicatorCounted();
   if(Bars<=21) return(0);    
     if(counted_bars<=0)      
      {limit=Bars-21-1;}
      else
       {limit=Bars-counted_bars;}  
 
 for(cnt=limit;cnt>=0;cnt--)
  {
   line1[cnt]=iMA(NULL,0,21,0,MODE_SMA,PRICE_HIGH,cnt);
   line2[cnt]=iMA(NULL,0,21,0,MODE_SMA,PRICE_LOW,cnt);
   line3[cnt]=(line1[cnt]+line2[cnt])/2;
  }
  
 for(cnt=limit;cnt>=0;cnt--)
 {
   line4[cnt] = iMAOnArray(line3,0,21,0,MODE_SMA,cnt);
 }
return(0);
}

при присоединении индикатора к графику видим следующую картинку



но при визуализации тестирования советника использующего данный индикатор картинка меняется


соответственно, тестер выдаёт полный бред.
код советника в прикреплённ ом файле, хотел и *.tpl приципить, не получилось, не вставляет и всё.

Но, если массив line3 сделать отображаемым, то с тестированием, визуализацией и результатами никаких проблем нету.
Разработчики, прошу прокомментировать ситуацию.

Файлы:
 
Попробуйте так:
//+------------------------------------------------------------------+
//|                                                     nigilist.mq4 |
//|                                                                  |
//|                                    'iMAOnArray некорректная работа функции на НЕ отображаемых массивах' |
//+------------------------------------------------------------------+
#property copyright "nigilist"
#property link      "nigilist_t@mail.ru"
//установки окна индикатора---------
#property indicator_chart_window
#property indicator_buffers 3
//----------------------------------
//предустановки линий------------------------------
#property indicator_color1 Red        
#property indicator_width1 1
#property indicator_style1 1
#property indicator_color2 Blue        
#property indicator_width2 1
#property indicator_style2 1 
#property indicator_color3 CornflowerBlue     
#property indicator_width3 3
#property indicator_style3 1
//-------------------------------------------------
//внутрение переменные-----------------------------
int cnt, limit;
//буфферы------------------------------------------
double line1[], line2[], line3[],line4[];
//-------------------------------------------------
 
int init()
{
//линии индикатора---------------------------------
IndicatorBuffers(4);
 SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, line1);
 SetIndexLabel(0, "resistance");
      
 SetIndexStyle(1, DRAW_LINE);
SetIndexBuffer(1, line2);
 SetIndexLabel(1, "support");
 
 SetIndexStyle(2, DRAW_LINE);
SetIndexBuffer(2, line4);
 
 SetIndexBuffer(4, line3);
 
//------------------------------------------------
//изменение индексации в сформированных массивах--
ArraySetAsSeries(line3,true);
//------------------------------------------------
}
 
int start()
{
 int counted_bars=IndicatorCounted();
   if(Bars<=21) return(0);    
     if(counted_bars<=0)      
      {limit=Bars-21-1;}
      else
       {limit=Bars-counted_bars;}  
 
 for(cnt=limit;cnt>=0;cnt--)
  {
   line1[cnt]=iMA(NULL,0,21,0,MODE_SMA,PRICE_HIGH,cnt);
   line2[cnt]=iMA(NULL,0,21,0,MODE_SMA,PRICE_LOW,cnt);
   line3[cnt]=(line1[cnt]+line2[cnt])/2.0;
  }
  
 for(cnt=limit;cnt>=0;cnt--)
 {
   line4[cnt] = iMAOnArray(line3,0,21,0,MODE_SMA,cnt);
 }
return(0);
}
 

Как я понял без SetIndexBuffer не обойтись.

 
//+------------------------------------------------------------------+
//|                                                     nigilist.mq4 |
//|                                              'iMAOnArray некорректная работа функции на НЕ отображаемых массивах' |
//+------------------------------------------------------------------+
#property copyright "nigilist"
#property link      "nigilist_t@mail.ru"
// установки окна индикатора
#property indicator_chart_window
#property indicator_buffers 3
// предустановки линий
#property indicator_color1 Red       
#property indicator_color2 Blue        
#property indicator_color3 Brown
#property indicator_width3 3
#property indicator_style3 1     
// буфферы 
double line1[], line2[], line3[], line4[];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
// линии индикатора
   IndicatorBuffers(4);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, line1);
   SetIndexLabel(0, "resistance");
//----      
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, line2);
   SetIndexLabel(1, "support");
//---- 
   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(2, line3);
   SetIndexLabel(2, "smoothed");
//----
   SetIndexBuffer(3, line4);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int cnt, limit;
   int counted_bars = IndicatorCounted();
   if(Bars < 21) 
       return(0);    
   if(counted_bars < 0)      
       return(0);   
   limit = Bars - counted_bars;
   for(cnt = limit; cnt >= 0; cnt--)
     {
       line1[cnt] = iMA(NULL, 0, 21, 0, MODE_SMA, PRICE_HIGH, cnt);
       line2[cnt] = iMA(NULL, 0, 21, 0, MODE_SMA, PRICE_LOW, cnt);
       line4[cnt] = NormalizeDouble((line1[cnt] + line2[cnt]) / 2.0, Digits);
     }
   for(cnt = limit; cnt >= 0; cnt--)
       line3[cnt] = iMAOnArray(line4, 0, 21, 0, MODE_SMA, cnt);
   return(0);
  }
//+------------------------------------------------------------------+




 

На самом деле работа корректная, если вынести заполнение line3 в другой цикл

 for(cnt=0; cnt<Bars; cnt++)
    line3[cnt]=(line1[cnt]+line2[cnt])/2;

Не забывайте о том, что управлением индексных массивов занимается терминал, а управлением локальных массивов типа line3 - никто

Причина обращения: