CSVでデータを出力し続けるプログラムを、上書き方式に変更したい
コード #property strict input int MaxBars = 1000;//出力したいデータ量を入力(ろうそくの本数) input string WriteFileName = "Test.csv"; //出力したいファイル名を入力 int handle = INVALID_HANDLE; int OnInit() { handle = FileOpen(WriteFileName, FILE_CSV | FILE_WRITE | FILE_SHARE_READ, ","); if (handle == INVALID_HANDLE) { return INIT_FAILED; } FileWrite(handle, ServerAddress(), Symbol(), Period()); FileWrite(handle, "DATE", "TIME", "OPEN", "HIGH", "LOW", "CLOSE", "VOLUME"); return INIT_SUCCEEDED; } void OnDeinit(const int) { FileClose(handle); } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { static datetime prevTime = 0; datetime currTime = iTime(NULL, PERIOD_CURRENT, 0); if(currTime == prevTime) { return rates_total; } prevTime = currTime; int limit = Bars - IndicatorCounted() - 1; limit = MathMin(limit, MaxBars); for(int i = limit; i >= 1; i--) { FileWrite(handle, StringFormat("%04d/%02d/%02d", TimeYear(Time[i]), TimeMonth(Time[i]), TimeDay(Time[i])), TimeToString(Time[i], TIME_MINUTES), Open[i], High[i], Low[i], Close[i], Volume[i]); } FileFlush(handle); Comment(WriteFileName + " はMQL4>File フォルダに出力されました。 " + TimeToStr(prevTime, TIME_SECONDS) ); return(rates_total); }```
回答1件
あなたの回答
tips
プレビュー