Помогите исправить код. - страница 2

 

Есть такая проблема: начиная с некоторого момента до конца баров (от младшего до последнего) значение для первой линии становится константой и значительно отличается от реальной.

 

for(i=pos;i>=0;i--)

  {

//--- Calculate the shift bars of prev_period & next_period

  prev_period_shift = iBarShift(NULL,prev_period,Time[i],false);

  next_period_shift = iBarShift(NULL,next_period,Time[i],false);

//--- 

  if(Aver_Bars<0) Aver_Bars=0;

  double prev_sum=0.0, sum=0.0, next_sum=0.0;

  for(n=0;n<=Aver_Bars;n++)

   {

   prev_sum = prev_sum + iClose(NULL,prev_period,prev_period_shift+n);

   sum = sum+Close[i+n];

   next_sum = next_sum + iClose(NULL,next_period,next_period_shift+n);

   }

   Prev_period[i] = prev_sum/(Aver_Bars+1);

   This_period[i] = sum/(Aver_Bars+1);

   Next_period[i] = next_sum/(Aver_Bars+1);

  }