
#property show_inputs
extern string ext="txt";
extern int last_bar=1;
extern int bars=610;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
double o,hi,l,c,v; 

   int h=FileOpen(Symbol()+Period()+"."+ext+"",FILE_WRITE|FILE_CSV,",");
      for(int i=bars;i>=last_bar;i--)
      {
         o=iOpen(Symbol(),Period(),i);
         c=iClose(Symbol(),Period(),i);
         hi=iHigh(Symbol(),Period(),i);
         l=iLow(Symbol(),Period(),i);
         v=iVolume(Symbol(),Period(),i);
         
         FileWrite(h,TimeToStr(Time[i],TIME_DATE),TimeToStr(Time[i],TIME_MINUTES),o,hi,l,c,v);
      }
    FileClose(h);
    PlaySound("alert.wav");

//----
   return(0);
  }
//+------------------------------------------------------------------+