[新手請教][OnTimer 使用問題]

 

我想要測試OnTimer是否每分鐘會執行一次,

所以OnInit()裡面設定EventSetTimer(60),並且在OnTimer()裡加入Print("OnTimer");

讓程式每分鐘print "OnTimer"一次,但是在"日誌"裡面卻沒看到印出任何的東西,

請問是還少設定什麼嗎?

下面附上測試的code,

感謝。

 

//+------------------------------------------------------------------+
//|                                                      ttttttt.mq4 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
      
//---
   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");
  
  }

自动交易和策略测试
自动交易和策略测试
  • www.mql5.com
MQL5:MetaTrader 5客户端内置的交易策略语言。语言允许编写您自己的自动交易系统,技术指标,脚本和函数程序库
 

这段代码运行没问题。

你可以先把 60 改为 3,这样可以加快调试速度。

原因: