problem with indicator

 
#property copyright "Copyright 2013, B.Y"
#property link      "Boaz@UTrade.co.il"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red

//---- input parameters
extern int       period = 26;
extern int       histper = 26;

double VID[];
double VID_Gap[];
//+------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------+
int init()
  {
  
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,VID);
   SetIndexLabel(0, "VID");
   SetIndexStyle(1,DRAW_NONE);
   SetIndexBuffer(1,VID_Gap);
   SetIndexLabel(1, "VID_Gap");
//----

   return(0);
  }
int deinit()
  {
   return(0);
  }
//+-------------------------------------+
//| Custom indicator iteration function |
//+-------------------------------------+
int start()
  {
  
   int    counted_bars=IndicatorCounted();//counted_bars=0 
   int    i, mult;
   double sc, k;
//----
Print("counted_bars=", counted_bars, ",Bars=", Bars);
Print(period);
   if (Digits>3) mult=10000;
   else          mult=100;
   i = Bars - counted_bars-1;//bars=1001  counted_bars=0 
   Print(i,Bars,counted_bars);
   while (i>0){//from 1001 to 0
         k =  CalculateCMO(i);
         sc = (2.0 / (period + 1));
         VID[i] = k * sc * Close[i] + (1 - k * sc) * VID[i+1];
         VID_Gap[i] = MathRound(mult*(VID[i]-Close[i]));
    int vidy=FileOpen("vidyametay1233.csv", FILE_CSV|FILE_READ|FILE_WRITE,';');
     FileSeek(vidy,0, SEEK_END);
     FileWrite(vidy,VID[i],",",TimeToStr(TimeCurrent()),",",i,",",Bars,",",counted_bars) ;
    FileClose(vidy);  
     vidy=0;
      i--;
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
double CalculateCMO(int Pos)
{
      double UpSum=0,DownSum=0,resCMO=0;
      for(int i=0;i<period;i++)
        {
         double diff=Close[i]-Close[i+1];
         if(diff>=0.0)
            UpSum+=diff;
         else
            DownSum+=(-diff);
        }
      if(UpSum+DownSum!=0.0)
         resCMO=(UpSum-DownSum)/(UpSum+DownSum);

  return(MathAbs(resCMO));
}
//+-------------------------------------

hi,

I try to write a new indicator that base in min revertion.

I print the result to CSV file

for some reason the indicator print 1000 result before it begin to trade ( I attach a file with my indicator code)

any help will be appriciate

 
idantrade:


for some reason the indicator print 1000 result before it begin to trade ( I attach a file with my indicator code)

Indicators cannot trade . . . can you please explain what you mean ?
Reason: