各位高手,老师,在网上苦苦寻得一段输出商品报价的指标..但不知为何只能在载入时输出一次,并不能实时输出..(输出文件在MT4的FILE文件中),能否帮改下或是需要如何设置MT4软件才能达到自定义指标实时刷新吗? 谢谢各位..代码如下:
#include
#property indicator_chart_window
int last_write_period=0;
extern int MAX_ROWS = 3000;
extern string START_DATE = "2008-1-1";
int init() {
writelog();
return (0);
}
int writelog() {
int i, cnt, hlog, tm;
string date = Symbol();
date = StringSubstr(date, 0, 1)+StringSubstr(date, 3, 1);
string hour = Symbol();
hour = StringSubstr(hour, 0, 1)+StringSubstr(hour, 3, 1);
string fname = date+"_";
cnt = Period();
if (cnt==PERIOD_M1) fname = fname+"M1.txt";
if (cnt==PERIOD_M5) fname = fname+"M5.txt";
if (cnt==PERIOD_M15) fname = fname+"M15.txt";
if (cnt==PERIOD_M30) fname = fname+"M30.txt";
if (cnt==PERIOD_H1) fname = fname+"H1.txt";
if (cnt==PERIOD_H4) fname = fname+"H4.txt";
if (cnt==PERIOD_D1) fname = fname+"D1.txt";
if (cnt==PERIOD_W1) fname = fname+"W1.txt";
if (cnt==PERIOD_MN1) fname = fname+"MN.txt";
cnt = CurTime() / (cnt*60);
if (cnt!=last_write_period) {
hlog = FileOpen(fname, FILE_CSV | FILE_WRITE, " ");
if (hlog=0; i--) {
tm = Time[i];
date = TimeToStr(tm, TIME_DATE);
hour=TimeToStr(tm, TIME_MINUTES);
//s output eg:2011.08.2519:00
date= StringSubstr(date,0,4)+"/"+StringSubstr(date,5,2)+"/"+StringSubstr(date,8,2);
if (Open[i]!=0 && High[i]!=0) {
FileWrite(hlog, date, hour,Open[i], High[i], Low[i], Close[i]);
}
}
FileClose(hlog);
last_write_period = cnt;
Print("输出GET数据文件成功.");
Comment(TimeToStr(CurTime(), TIME_DATE), " ", TimeToStr(CurTime(), TIME_MINUTES), ":输出GET数据文件成功.");
}
return (0);
}
int start() {
return ( writelog() );
}
|