/* * Library Sample. */ // a link to the company website #property link "" // the company name #property copyright "" /* * ファイルを開く. * return file handle. * not -1 : opened file * -1 : fail */ int openFile() { /* * FileOpen. * http://docs.mql4.com/files/FileOpen */ int handle = FileOpen(OUTPUT_FILE_NAME, FILE_CSV|FILE_READ|FILE_WRITE, ","); if (handle != -1) { FileSeek(handle, 0, SEEK_END); } else { int errorCode = GetLastError(); Print("Cannot open file. [name:", OUTPUT_FILE_NAME, "][errorCode:", errorCode, "]"); } return(handle); } /* * ファイルを閉じる. */ void closeFile(int handle) { FileClose(handle); } /* * ファイルに文字列を書く. */ void writeFile(int handle, string typeName, string message) { datetime current = TimeCurrent(); int result = FileWrite( handle, datetime2String(current), typeName, message); if (result >= 0) { FileFlush(handle); return; } int errorCode = GetLastError(); Print("Cannot write file. [name:", OUTPUT_FILE_NAME, "][errorCode:", errorCode, "]"); return; } /* * ファイルに出力する. */ void output(string message) { if (!DEBUG) { return; } int handle = openFile(); if (handle == -1) { return; } writeFile(handle, "info", message); closeFile(handle); }