//+------------------------------------------------------------------+ //| SavePrices.mq4 | //| John Taylor | //| http://www.linkedin.com/in/johntaylorhk | //+------------------------------------------------------------------+ #property copyright "John Taylor" #property link "http://www.linkedin.com/in/johntaylorhk" #include extern string FileNameRoot="DailyPrices"; int init() { return(0); } int deinit() { return(0); } int start() { static datetime prevTime=0; if (prevTime!=Time[0]) { if (prevTime!=0) { // ensure 1st tick is on a candle start SavePrices(); } prevTime=Time[0]; } return(0); } void SavePrices() { string fileName=StringConcatenate(TimeToStr(Time[0],TIME_DATE)," - ",Symbol()," - ",FileNameRoot,".csv"); int handle=FileOpen(fileName,FILE_CSV|FILE_WRITE|FILE_READ,","); if(handle>=0) { FileSeek(handle,0,SEEK_END); } else { handle=FileOpen(fileName,FILE_CSV|FILE_WRITE,","); } if(handle<0) Alert("No file called ", fileName,"could be opened or created"); else { if(FileWrite(handle,Symbol(), TimeToStr(Time[0]), DoubleToStr(Open [1],Digits), DoubleToStr(High [1],Digits), DoubleToStr(Low [1],Digits), DoubleToStr(Close[1],Digits), Volume[1])<0) { Alert("SavePrices: FileWrite failed - ",ErrorDescription(GetLastError())); } } if(handle>=0) FileClose(handle); }