//+------------------------------------------------------------------+ //| LogUtils.mqh | //| Paul Hampton-Smith | //| paul1000@pobox.com | //+------------------------------------------------------------------+ int nDaysSince1970 = 0; int LogHandle = -1; bool bEnableLogging = false; // set this true in EA init() void OpenLog(string strName) { if (!bEnableLogging) return; if (TimeCurrent()/(60*60*24) > nDaysSince1970 || LogHandle <= 0 ) { // startup or new day if (LogHandle > 0) FileClose(LogHandle); string strMonthPad = ""; string strDayPad = ""; if (Month()<10) strMonthPad = "0"; if (Day()<10) strDayPad = "0"; string strFilename = StringConcatenate(strName,"_",Year(),strMonthPad,Month(),strDayPad,Day(),"_log.txt"); LogHandle = FileOpen(strFilename,FILE_CSV|FILE_READ|FILE_WRITE); nDaysSince1970 = TimeCurrent()/(60*60*24); } FileFlush(LogHandle); FileSeek(LogHandle,0,SEEK_END); } void Log(string msg) { if (!bEnableLogging) return; if (LogHandle <= 0) return; msg = TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS) + " " + msg; FileWrite(LogHandle,msg); } void LogFlush() { FileFlush(LogHandle); }