MQL5参考经济日历函数CalendarValueHistoryByEvent 

CalendarValueHistoryByEvent

根据事件ID获得指定时期的所有事件值数组。

bool  CalendarValueHistoryByEvent(
   ulong              event_id,          // 事件ID 
   MqlCalendarValue&  values[],          // 值描述数组
   datetime           datetime_from,     // 时间范围的左边框
   datetime           datetime_to=0      // 时间范围的右边框
   );

参数

event_id

[in]  事件ID。

values[]

[out] MqlCalendarValue类型数组,用于接收事件值。

datetime_from

[in]  时间范围事件的初始日期通过指定ID选择,而datetime_from < datetime_to

datetime_to=0

[in]  时间范围事件的结束日期通过指定ID选择。如果datetime_to 没有设置(或设置为0),那么返回在“日历”数据库中从指定datetime_from日期开始的所有事件值(包括未来事件的值)。

返回值

如果成功返回true,否则返回false。若要获得有关错误的信息,请调用GetLastError()函数。可能错误:

  • 4001 – ERR_INTERNAL_ERROR(一般运行时错误)。
  • 4004 – ERR_NOT_ENOUGH_MEMORY(内存不足,无法执行请求)。
  • 5401 – ERR_CALENDAR_TIMEOUT(超过请求时限)。
  • 5400 – ERR_CALENDAR_MORE_DATA(数组大小不足以接收所有值的描述,只可以接收那些适合的值)。

如果事件值没有下面指定的任何字段

struct MqlCalendarValue
  {
   ...
   long              actual_value;              // 事件的实际值
   long              prev_value;                // 事件的前值
   long              revised_prev_value;        // 事件修正后的前值
   long              forecast_value;            // 事件的预测值
   ...
  };

然后返回失去字段的值INT64_MIN (-9223372036854775808)。在以下示例中查阅revised_prev_value字段值。

例如:

//+------------------------------------------------------------------+
//| 脚本程序起始函数                                                     |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- 欧盟国家代码(ISO 3166-1 Alpha-2)
   string EU_code="EU";
//--- 获得欧盟事件
   MqlCalendarEvent events[];
   int events_count=CalendarEventByCountry(EU_code,events);
//--- 在“日志”中显示欧盟事件
   if(events_count>0)
     {
      PrintFormat("EU events: %d",events_count);
      //--- 减少事件列表,10个事件足以分析
      ArrayResize(events,10);
      ArrayPrint(events);
     }
//--- 查阅“ECB利率决策”事件event_id=999010007
   ulong event_id=events[6].id;        // 事件ID可在“日历”中更改,因此一定进行验证
   string event_name=events[6].name;   // “日历”事件的名称
   PrintFormat("Get values for event_name=%s event_id=%d",event_name,event_id);
//--- 获得“ECB利率决策”事件的所有值
   MqlCalendarValue values[];
//--- 设置事件发生间隔的边界
   datetime date_from=0;           // 获取可用历史开始的所有事件
   datetime date_to=D'01.01.2016'; // 获取2016年以后的事件
   if(CalendarValueHistoryByEvent(event_id,values,date_from,date_to))
     {
      PrintFormat("Received values for %s: %d",
                  event_name,ArraySize(values));
      //--- 减少值列表,10个事件足以分析
      ArrayResize(values,10);
      ArrayPrint(values);
     }
   else
     {
      PrintFormat("Error! Failed to get values for event_id=%d",event_id);
      PrintFormat("Error code: %d",GetLastError());
     }
  }
//---
/*
  结果:
  欧盟事件:56
            [id] [type] [sector] [frequency] [time_mode] [country_id] [unit] [importance] [multiplier] [digits]                                        [source_url]                                 [event_code]                                    [name] [reserv
   [0] 999010001      0        5           0           0          999      0            2            0        0 "https://www.ecb.europa.eu/home/html/index.en.html" "ecb-non-monetary-policy-meeting"            "ECB Non-monetary Policy Meeting"                
   [1] 999010002      0        5           0           0          999      0            2            0        0 "https://www.ecb.europa.eu/home/html/index.en.html" "ecb-monetary-policy-meeting-accounts"       "ECB Monetary Policy Meeting Accounts"           
   [2] 999010003      0        5           0           0          999      0            3            0        0 "https://www.ecb.europa.eu/home/html/index.en.html" "ecb-monetary-policy-press-conference"       "ECB Monetary Policy Press Conference"           
   [3] 999010004      0        5           0           0          999      0            3            0        0 "https://www.ecb.europa.eu/home/html/index.en.html" "ecb-president-draghi-speech"                "ECB President Draghi Speech"                    
   [4] 999010005      0        5           0           0          999      0            2            0        0 "https://www.ecb.europa.eu/home/html/index.en.html" "ecb-vice-president-vitor-constancio-speech" "ECB Vice President Constancio Speech"           
   [5] 999010006      1        5           0           0          999      1            3            0        2 "https://www.ecb.europa.eu/home/html/index.en.html" "ecb-deposit-rate-decision"                  "ECB Deposit Facility Rate Decision"             
   [6] 999010007      1        5           0           0          999      1            3            0        2 "https://www.ecb.europa.eu/home/html/index.en.html" "ecb-interest-rate-decision"                 "ECB Interest Rate Decision"                     
   [7] 999010008      0        5           0           0          999      0            2            0        0 "https://www.ecb.europa.eu/home/html/index.en.html" "ecb-economic-bulletin"                      "ECB Economic Bulletin"                          
   [8] 999010009      1        5           0           0          999      2            2            3        3 "https://www.ecb.europa.eu/home/html/index.en.html" "targeted-ltro"                              "ECB Targeted LTRO"                              
   [9] 999010010      0        5           0           0          999      0            2            0        0 "https://www.ecb.europa.eu/home/html/index.en.html" "ecb-executive-board-member-praet-speech"    "ECB Executive Board Member Praet Speech"        
  获得event_name=ECB Interest Rate Decision值 event_id=999010007
  已接收的“ECB利率决策”事件值:102
       [id] [event_id]              [time]            [period] [revision] [actual_value] [prev_value] [revised_prev_value]     [forecast_value] [impact_type] [reserved]
   [0] 2776  999010007 2007.03.08 11:45:00 1970.01.01 00:00:00          0        3750000      4250000 -9223372036854775808 -9223372036854775808             0          0
   [1] 2777  999010007 2007.05.10 11:45:00 1970.01.01 00:00:00          0        3750000      3750000 -9223372036854775808 -9223372036854775808             0          0
   [2] 2778  999010007 2007.06.06 11:45:00 1970.01.01 00:00:00          0        4000000      3750000 -9223372036854775808 -9223372036854775808             0          0
   [3] 2779  999010007 2007.07.05 11:45:00 1970.01.01 00:00:00          0        4000000      4000000 -9223372036854775808 -9223372036854775808             0          0
   [4] 2780  999010007 2007.08.02 11:45:00 1970.01.01 00:00:00          0        4000000      4000000 -9223372036854775808 -9223372036854775808             0          0
   [5] 2781  999010007 2007.09.06 11:45:00 1970.01.01 00:00:00          0        4000000      4000000 -9223372036854775808 -9223372036854775808             0          0
   [6] 2782  999010007 2007.10.04 11:45:00 1970.01.01 00:00:00          0        4000000      4000000 -9223372036854775808 -9223372036854775808             0          0
   [7] 2783  999010007 2007.11.08 12:45:00 1970.01.01 00:00:00          0        4000000      4000000 -9223372036854775808 -9223372036854775808             0          0
   [8] 2784  999010007 2007.12.06 12:45:00 1970.01.01 00:00:00          0        4000000      4000000 -9223372036854775808 -9223372036854775808             0          0
   [9] 2785  999010007 2008.01.10 12:45:00 1970.01.01 00:00:00          0        4000000      4000000 -9223372036854775808 -9223372036854775808             0          0
*/

 

另见

CalendarCountriesCalendarEventByCountryCalendarValueHistoryCalendarEventByIdCalendarValueById