在MT当前图表中读取周期为1440的HST文件的MQ4脚本

此博客展示了一段C脚本代码,主要实现从文件中读取数据并处理。代码通过FileOpenHistory打开文件,读取版本、版权、符号等信息,计算记录总数,重新配置数组大小,将文件数据读入数组,最后关闭文件并发出结束提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//+------------------------------------------------------------------+
//|                                                  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);
  }
//+------------------------------------------------------------------+

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值