下载MetaTrader 5

貌似MT4的EventSetTimer不支持复盘?

要添加评论,请登录注册
Amy Liu
645
Amy Liu  

写了一个学习使用MQL4中Timer时间事件的小程序,发现一些问题,怀疑EventSetTimer不支持复盘。相关帮助文件中好像没有这方面的说明,所以拿出来跟大家求证一下。

首先,代码如下:

//+------------------------------------------------------------------+
//|                                                    TimerTest.mq4 |
//|                                       Copyright 2014, aforexpert. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, aforexpert."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict

//+------------------------------------------------------------------+
//| expert include                                                   |
//+------------------------------------------------------------------+
#include <stdlib.mqh>

//--- input parameters
input ushort   seconds=300;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   if(!EventSetTimer(seconds))
     {
      int error=GetLastError();
      PrintFormat("EventSetTimer FAILED: #%d[%s]", error, ErrorDescription(error));
     }
      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   Print("OnTimer");
  }
//+------------------------------------------------------------------+

编译无报错;

复盘设置如下:

 

复盘报错:“2014.09.06 10:26:26.023 2014.09.01 00:00 TimerTest EURUSD,M1: EventSetTimer FAILED: #4051[invalid function parameter value]” ;

最后,在模拟账户上加载运行,初始化完成,EventSetTimer无报错且正确运行:

 

enbo lu
版主
1950
enbo lu  
OnTimer 和 OnChartEvent 都不支持 策略测试器
Amy Liu
645
Amy Liu  
luenbo:
OnTimer 和 OnChartEvent 都不支持 策略测试器

恩,谢谢! 

要添加评论,请登录注册