EA Script or Indicator to save Live incoming Tick data as CSV

 

Hi there I've been trying to write a solution  to save Live incoming Tick data as CSV, 1 symbol is fine but for all symbols on marketwatch automatically it fails can anyone figure it out?


This is my code:


//------------------------------------------------------------------

#property copyright "www.forex-tsd.com"

#property link      "www.forex-tsd.com"

//------------------------------------------------------------------

#property indicator_chart_window


//

//

//

//

//

input ENUM_TIMEFRAMES InpTimeFrame=PERIOD_M5; // Timeframe for all markwatch symbols

input ENUM_SYMBOL_INFO_STRING = symbolname;

extern string FileName= "Ticks.csv";

int fileHandle;

string symbol;

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

//

//


int init()  

 { 

       

      fileHandle =FileOpen (symbol+FileName, FILE_CSV|FILE_READ|FILE_WRITE|FILE_REWRITE,',');

          

 return(0);

  }

  

int deinit()

 {             

  FileClose(fileHandle);     

    return(0);

     }

int start()

{

   int nSymbols=SymbolsTotal(true);

   

  for(int i=0; i<nSymbols && !IsStopped(); i++){

   symbol=SymbolName(i,true); 

      fileHandle =FileOpen (symbol+FileName, FILE_CSV|FILE_READ|FILE_WRITE|FILE_REWRITE,',')

     FileWrite(fileHandle,"date and time,bid,ask,volume\n");

   

if(fileHandle > 0 ){

    FileWrite(fileHandle,TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)+","+DoubleToStr(Bid,Digits)+","+DoubleToStr(Ask,Digits)+","+DoubleToStr(Volume[0],0)+"\n");

      }

      

       if((i & 127)==127)

           {

            //--- now, data will be located in the file and will not be lost in case of a critical error

            FileFlush(fileHandle);

            PrintFormat("i = %d, OK",i);

           }

         //--- 0.01 second pause

         Sleep(10);

      }

      FileClose(fileHandle)   

  return(0);

   }         

  


 
Please edit your post and use the code button (Alt+S) to paste code.


In future please post in the correct section
I will move your topic to the MQL4 and Metatrader 4 section.