OnInit()の中でファイルを一行だけ読み込んでコピーを出力するプログラム。
しかし、実際には全てコピーされて出力されたファイルの最後の部分もおかしい。
//+------------------------------------------------------------------+
//| File_Test.mq5 |
//| Copyright 2012, MetaQuotes Software Corp. |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link ""
#property version "1.00"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
int handle_read = FileOpen("USDJPY-5min_2010.txt", FILE_CSV| FILE_READ, ',');
int handle_write = FileOpen("copy.csv", FILE_CSV | FILE_WRITE, ',');
string day = FileReadString(handle_read, 10);
string time = FileReadString(handle_read, 8);
double open_price = FileReadDouble(handle_read);
double high_price = FileReadDouble(handle_read);
double low_price = FileReadDouble(handle_read);
double close_price = FileReadDouble(handle_read);
FileClose(handle_read);
FileWrite(handle_write, day, time, open_price, high_price, low_price, close_price);
FileClose(handle_write);
//---
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
//---
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
■オープンするファイル USDJPY-5min_2010.txt の内容
(日付、時刻、始値、高値、安値、終値の順で並んでいてカンマで区切られている)
2010/01/04,07:00:00,92.96,92.97,92.95,92.96
2010/01/04,07:05:00,92.96,93.06,92.95,93.06
2010/01/04,07:10:00,93.06,93.06,93.05,93.05
2010/01/04,07:15:00,93.04,93.06,93.02,93.04
2010/01/04,07:20:00,93.04,93.06,93.03,93.05
2010/01/04,07:25:00,93.05,93.06,93.04,93.06
:
: (省略)
:
:
2010/09/10,07:55:00,83.81,83.82,83.79,83.81
2010/09/10,08:00:00,83.81,83.81,83.81,83.81
■コピーしたファイル copy.csv の内容
2010/01/04,07:00:00,92.96,92.97,92.95,92.96
2010/01/04,07:05:00,92.96,93.06,92.95,93.06
2010/01/04,07:10:00,93.06,93.06,93.05,93.05
2010/01/04,07:15:00,93.04,93.06,93.02,93.04
2010/01/04,07:20:00,93.04,93.06,93.03,93.05
2010/01/04,07:25:00,93.05,93.06,93.04,93.06
:
: (省略)
:
:
2010/09/10,07:55:00,83.81,83.82,83.79,83.81
2010/09/10,08:00:00,83.81,83.81,83.81,83.8, , 0 , 0 , 0 , 0
■USDJPY-5min_2010.txt の入手
http://www.ibi-square.jp/kakodata.shtml
ドル円の5分足、2010年度版
