程序库: 日历 - 页 11

 
amrali #:

直接从 12:30 减去(而不是 -3 + 31*/2):

我不是故意这样做的,因为我认为将来有可能更改 CalendarValueHistoryByEvent 的输入参数。

 
fxsaber #:

我不是故意这样做的,因为我认为将来有可能更改 CalendarValueHistoryByEvent 的输入参数。

您可以使用

   return((int)(45000 - Value[0].time % 86400));
 
fxsaber #:

更新资料库后,日历应与任何经纪商的历史报价同步。

...

最新版本是否删除了按时间排序的功能?


 
Anatoli Kazharski #:

他们是否在最新版本中取消了时间排序?

是的,我确信 MQ 是排序的。我错了。


已添加 ZY。

 

不幸的是,您不能相信当前的日历。


以下是事件列表中遗漏的一条重要瑞士法郎新闻,以及相应的市场反应。


这是另一份日历,其中有该新闻。


 

在《教程》中,我发现了一个关于如何使用日历的信息宝库。尤其是在测试器中

Теперь мы можем выбрать индикатор CalendarMonitorCached.mq5  в тестере и увидеть в динамике, на истории, как меняется таблица новостей.

测试器中带有日历缓存的新闻指标

日历缓存的存在使您可以测试新闻交易策略。我们将在下一节展示。

它使用与本地 MQL5 日历相同的 API。
Учебник по MQL5: Расширенные средства языка / Экономический календарь / Перенос базы календаря в тестер
Учебник по MQL5: Расширенные средства языка / Экономический календарь / Перенос базы календаря в тестер
  • www.mql5.com
Календарь доступен для MQL-программ только в режиме онлайн, в связи с чем тестирование новостных торговых стратегий представляет некоторую...
 

代码相同,图表符号不同,结果也不同。我测试了 2 家经纪商。

test_calendar.mq5

#include "Calendar.mqh"

void OnStart()
  {
   CALENDAR Calendar;

   if(Calendar.Set(NULL, CALENDAR_IMPORTANCE_NONE, D'2023.10.1', TimeCurrent()))
     {
      Calendar.FilterByEventID(840030016); // NFP

      Calendar.AutoDST();

      Print(Calendar.ToString());
     }
  }

FXOpen:

test_calendar (EURUSD,M1)       2023.10.06 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 336 K | 1 K | 187 K | 227 K
test_calendar (EURUSD,M1)       2023.11.03 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 150 K | -8 K | 336 K | 297 K
test_calendar (EURUSD,M1)       2023.12.08 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | -3 K | 150 K | 
test_calendar (EURUSD,M1)       2024.01.05 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 216 K | 1 K | 199 K | 173 K
test_calendar (EURUSD,M1)       2024.02.02 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 353 K | 186 K | 216 K | 333 K
test_calendar (EURUSD,M1)       2024.03.08 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 275 K | 220 K | 353 K | 229 K
test_calendar (EURUSD,M1)       2024.04.05 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 303 K | 176 K | 275 K | 270 K
test_calendar (EURUSD,M1)       
test_calendar (XAUUSD,M1)       2023.10.06 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 336 K | 1 K | 187 K | 227 K
test_calendar (XAUUSD,M1)       2023.11.03 14:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 150 K | -8 K | 336 K | 297 K
test_calendar (XAUUSD,M1)       2023.12.08 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | -3 K | 150 K | 
test_calendar (XAUUSD,M1)       2024.01.05 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 216 K | 1 K | 199 K | 173 K
test_calendar (XAUUSD,M1)       2024.02.02 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 353 K | 186 K | 216 K | 333 K
test_calendar (XAUUSD,M1)       2024.03.08 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 275 K | 220 K | 353 K | 229 K
test_calendar (XAUUSD,M1)       2024.04.05 15:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 303 K | 176 K | 275 K | 270 K
test_calendar (XAUUSD,M1)       
BrokerDaylightSchedule (XAUUSD,M1)      Server : FXOpen-MT5
BrokerDaylightSchedule (XAUUSD,M1)      Time   : 2024.04.13 03:05:59
BrokerDaylightSchedule (XAUUSD,M1)      Offset : GMT+3
BrokerDaylightSchedule (XAUUSD,M1)      DST_US : server dst begins on the second Sunday of March (+1) and ends on the first Sunday of November (-1)

Trading.com

test_calendar (EURUSD,H4)       2023.10.06 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 336 K | 1 K | 187 K | 227 K
test_calendar (EURUSD,H4)       2023.11.03 07:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 150 K | -8 K | 336 K | 297 K
test_calendar (EURUSD,H4)       2023.12.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | -3 K | 150 K | 
test_calendar (EURUSD,H4)       2024.01.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 216 K | 1 K | 199 K | 173 K
test_calendar (EURUSD,H4)       2024.02.02 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 353 K | 186 K | 216 K | 333 K
test_calendar (EURUSD,H4)       2024.03.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 275 K | 220 K | 353 K | 229 K
test_calendar (EURUSD,H4)       2024.04.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 303 K | 176 K | 275 K | 270 K
test_calendar (EURUSD,H4)       
test_calendar (USDJPY,H1)       2023.10.06 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 336 K | 1 K | 187 K | 227 K
test_calendar (USDJPY,H1)       2023.11.03 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 150 K | -8 K | 336 K | 297 K
test_calendar (USDJPY,H1)       2023.12.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | -3 K | 150 K | 
test_calendar (USDJPY,H1)       2024.01.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 216 K | 1 K | 199 K | 173 K
test_calendar (USDJPY,H1)       2024.02.02 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 353 K | 186 K | 216 K | 333 K
test_calendar (USDJPY,H1)       2024.03.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 275 K | 220 K | 353 K | 229 K
test_calendar (USDJPY,H1)       2024.04.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 303 K | 176 K | 275 K | 270 K
test_calendar (USDJPY,H1)       
BrokerDaylightSchedule (USDJPY,H1)      Server : Trading.comMarkets-MT5
BrokerDaylightSchedule (USDJPY,H1)      Time   : 2024.04.12 20:06:30
BrokerDaylightSchedule (USDJPY,H1)      Offset : GMT-4
BrokerDaylightSchedule (USDJPY,H1)      DST_US : server dst begins on the second Sunday of March (+1) and ends on the first Sunday of November (-1)

我找到了错误的根源:DST::IsEurope() 错误地为这些 DST_US 经纪商返回 true,因为 DST::RolloverTime() 中的算法不可靠(即扫描点差)。

test_calendar_fixed.mq5

#include "Calendar.mqh"
#include "TimeZoneInfo.mqh"  //https://www.mql5.com/en/code/48419

void OnStart()
  {
   CALENDAR Calendar;

   if(Calendar.Set(NULL, CALENDAR_IMPORTANCE_NONE, D'2023.10.1', TimeCurrent()))
     {
      Calendar.FilterByEventID(840030016); // NFP

      //Calendar.AutoDST();

      //-----------------------------------------------------------------------
      EVENT eEvents[];
      Calendar.GetEvents(eEvents);  // 提取事件。

      for(int i = ArraySize(eEvents) - 1; i >= 0; i--)
        {
         if(eEvents[i].TimeMode == CALENDAR_TIMEMODE_DATETIME ||
            eEvents[i].TimeMode == CALENDAR_TIMEMODE_TENTATIVE)
           {
            //--- 转换服务器时间 -> GMT
            eEvents[i].time += DST::TimeServerGMTOffset();

            //-- 将格林尼治标准时间 -> 转换回服务器时间(使用正确的偏移量)
            eEvents[i].time = CTimeZoneInfo::ConvertTimeForPlace(eEvents[i].time, ZONE_ID_UTC, ZONE_ID_BROKER);
           }
        }

      Calendar = eEvents;  // 恢复事件
      //-----------------------------------------------------------------------

      Print(Calendar.ToString());
     }
  }

现在结果正确了:

test_calendar_fixed (EURUSD,H4) 2023.10.06 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 336 K | 1 K | 187 K | 227 K
test_calendar_fixed (EURUSD,H4) 2023.11.03 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 150 K | -8 K | 336 K | 297 K
test_calendar_fixed (EURUSD,H4) 2023.12.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | -3 K | 150 K | 
test_calendar_fixed (EURUSD,H4) 2024.01.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 216 K | 1 K | 199 K | 173 K
test_calendar_fixed (EURUSD,H4) 2024.02.02 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 353 K | 186 K | 216 K | 333 K
test_calendar_fixed (EURUSD,H4) 2024.03.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 275 K | 220 K | 353 K | 229 K
test_calendar_fixed (EURUSD,H4) 2024.04.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 303 K | 176 K | 275 K | 270 K
test_calendar_fixed (EURUSD,H4) 
test_calendar_fixed (USDJPY,H1) 2023.10.06 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 336 K | 1 K | 187 K | 227 K
test_calendar_fixed (USDJPY,H1) 2023.11.03 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 150 K | -8 K | 336 K | 297 K
test_calendar_fixed (USDJPY,H1) 2023.12.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | -3 K | 150 K | 
test_calendar_fixed (USDJPY,H1) 2024.01.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 216 K | 1 K | 199 K | 173 K
test_calendar_fixed (USDJPY,H1) 2024.02.02 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 353 K | 186 K | 216 K | 333 K
test_calendar_fixed (USDJPY,H1) 2024.03.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 275 K | 220 K | 353 K | 229 K
test_calendar_fixed (USDJPY,H1) 2024.04.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 303 K | 176 K | 275 K | 270 K
test_calendar_fixed (USDJPY,H1) 
BrokerDaylightSchedule (USDJPY,H1)      Server : Trading.comMarkets-MT5
BrokerDaylightSchedule (USDJPY,H1)      Time   : 2024.04.12 20:11:17
BrokerDaylightSchedule (USDJPY,H1)      Offset : GMT-4
BrokerDaylightSchedule (USDJPY,H1)      DST_US : server dst begins on the second Sunday of March (+1) and ends on the first Sunday of November (-1)

希望这能帮助您修复程序库。

 
amrali #:

代码相同,图表符号不同,结果也不同。我测试了 2 家经纪商。

我找到了错误的根源:DST::IsEurope() 错误地为这些 DST_US 经纪商返回 true,因为 DST::RolloverTime() 中执行的算法不可靠(即扫描点差)。


test_calendar_fixed.mq5

现在结果正确:

希望这能帮助您修复程序库。

非常感谢你找到了错误、提供了重现错误的示例以及建议的解决方案!


我已经修改了DST.mqh 文件。

 

DST_US 经纪商尚未完全固定。

test_calendar (USDJPY,H1)       2023.10.06 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 336 K | 1 K | 187 K | 227 K
test_calendar (USDJPY,H1)       2023.11.03 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 150 K | -8 K | 336 K | 297 K
test_calendar (USDJPY,H1)       2023.12.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | -3 K | 150 K | 
test_calendar (USDJPY,H1)       2024.01.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 216 K | 1 K | 199 K | 173 K
test_calendar (USDJPY,H1)       2024.02.02 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 353 K | 186 K | 216 K | 333 K
test_calendar (USDJPY,H1)       2024.03.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 275 K | 220 K | 353 K | 229 K
test_calendar (USDJPY,H1)       2024.04.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 303 K | 176 K | 275 K | 270 K
test_calendar (USDJPY,H1)       
test_calendar (EURUSD,H4)       2023.10.06 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 336 K | 1 K | 187 K | 227 K
test_calendar (EURUSD,H4)       2023.11.03 07:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 150 K | -8 K | 336 K | 297 K
test_calendar (EURUSD,H4)       2023.12.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | -3 K | 150 K | 
test_calendar (EURUSD,H4)       2024.01.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 216 K | 1 K | 199 K | 173 K
test_calendar (EURUSD,H4)       2024.02.02 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 353 K | 186 K | 216 K | 333 K
test_calendar (EURUSD,H4)       2024.03.08 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 275 K | 220 K | 353 K | 229 K
test_calendar (EURUSD,H4)       2024.04.05 08:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 303 K | 176 K | 275 K | 270 K
test_calendar (EURUSD,H4)       
BrokerDaylightSchedule (EURUSD,H4)      Server : Trading.comMarkets-MT5
BrokerDaylightSchedule (EURUSD,H4)      Time   : 2024.04.13 17:40:05
BrokerDaylightSchedule (EURUSD,H4)      Offset : GMT-4
BrokerDaylightSchedule (EURUSD,H4)      DST_US : server dst begins on the second Sunday of March (+1) and ends on the first Sunday of November (-1)

请注意,DST_NONE 经纪商还存在另一个问题:

test_calendar (EURUSDm,M5)      2023.10.06 12:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 336 K | 1 K | 187 K | 227 K
test_calendar (EURUSDm,M5)      2023.11.03 12:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 150 K | -8 K | 336 K | 297 K
test_calendar (EURUSDm,M5)      2023.12.08 12:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | -3 K | 150 K | 
test_calendar (EURUSDm,M5)      2024.01.05 12:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 216 K | 1 K | 199 K | 173 K
test_calendar (EURUSDm,M5)      2024.02.02 12:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 353 K | 186 K | 216 K | 333 K
test_calendar (EURUSDm,M5)      2024.03.08 12:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 275 K | 220 K | 353 K | 229 K
test_calendar (EURUSDm,M5)      2024.04.05 12:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 303 K | 176 K | 275 K | 270 K
test_calendar (EURUSDm,M5)      
test_calendar_fixed (EURUSDm,M5)        2023.10.06 12:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 336 K | 1 K | 187 K | 227 K
test_calendar_fixed (EURUSDm,M5)        2023.11.03 12:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 150 K | -8 K | 336 K | 297 K
test_calendar_fixed (EURUSDm,M5)        2023.12.08 13:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 199 K | -3 K | 150 K | 
test_calendar_fixed (EURUSDm,M5)        2024.01.05 13:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 216 K | 1 K | 199 K | 173 K
test_calendar_fixed (EURUSDm,M5)        2024.02.02 13:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 353 K | 186 K | 216 K | 333 K
test_calendar_fixed (EURUSDm,M5)        2024.03.08 13:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 275 K | 220 K | 353 K | 229 K
test_calendar_fixed (EURUSDm,M5)        2024.04.05 12:30 USD 3 Nonfarm Payrolls (nonfarm-payrolls), United States (US) | 303 K | 176 K | 275 K | 270 K
test_calendar_fixed (EURUSDm,M5)        
BrokerDaylightSchedule (EURUSDm,M5)     Server : Exness-MT5Trial
BrokerDaylightSchedule (EURUSDm,M5)     Time   : 2024.04.13 21:46:15
BrokerDaylightSchedule (EURUSDm,M5)     Offset : GMT+0
BrokerDaylightSchedule (EURUSDm,M5)     DST_NONE
因为 exness 服务器从未转换为 DST。因此,纽约时间上午 08:30 的 NFP 应与 Exness服务器时间(08:30 + 5:00 偏移量)= 13:30 一致。
 
fxsaber #:

不幸的是,你不能相信现在的《万年历》。

非常不幸的是,MQ-Calendar 在事件发生的时间上存在错误,即使是当天的事件也是如此。

新闻时间是 07:30(在上面的替代日历和符号图表上),而 MQ-Calendar 却说(包括网络版)新闻将在一小时后发布。