//+------------------------------------------------------------------+
//| wyhpractice.mq4 |
//| Copyright ?2005, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2005, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
int FHandle=-1;
//+------------------------------------------------------------------+
//| script program start function |
//+------------------------------------------------------------------+
int start()
{
//----
int version=400;
string c_copyright;
string c_symbol=Symbol();
int i_period=Period();
int i_digits=Digits;
int i_unused[13];
int zero=1;
int totalcount=0;
int ttime[];
double topen[], tlow[], thigh[], tclose[], tvolume[];
FHandle=FileOpenHistory(c_symbol+"1440.hst", FILE_BIN|FILE_READ);
version=FileReadInteger(FHandle,LONG_VALUE);
c_copyright=FileReadString(FHandle,64);
c_symbol=FileReadString(FHandle,12);
i_period=FileReadInteger(FHandle,LONG_VALUE);
i_digits=FileReadInteger(FHandle,LONG_VALUE);
zero=FileReadInteger(FHandle,LONG_VALUE);
zero=FileReadInteger(FHandle,LONG_VALUE);
FileReadArray(FHandle,i_unused, 0, 13);
//计算记录总数totalcount
totalcount=(FileSize(FHandle)-122)/44;
//重新配置数组大小
ArrayResize(ttime,totalcount);
ArrayResize(topen,totalcount);
ArrayResize(tlow,totalcount);
ArrayResize(thigh,totalcount);
ArrayResize(tclose,totalcount);
ArrayResize(tvolume,totalcount);
//将数据从文件读入数组中
int n=0;
while (n<totalcount)
{
ttime[n]=FileReadInteger(FHandle, LONG_VALUE);
topen[n]=FileReadDouble(FHandle, DOUBLE_VALUE);
tlow[n]=FileReadDouble(FHandle, DOUBLE_VALUE);
thigh[n]=FileReadDouble(FHandle, DOUBLE_VALUE);
tclose[n]=FileReadDouble(FHandle, DOUBLE_VALUE);
tvolume[n]=FileReadDouble(FHandle, DOUBLE_VALUE);
n=n+1;
}
//----
if(FHandle>=0) { FileClose(FHandle); FHandle=-1; }
Alert("End!!");
return(0);
}
//+------------------------------------------------------------------+
在MT当前图表中读取周期为1440的HST文件的MQ4脚本
最新推荐文章于 2024-02-20 11:29:59 发布