程序库: 日历 - 页 6

 
Automated Trading :

日历

作者:fxsaber

谢谢 fxsaber、
这个库太棒了。
请问 notepad++ 能否读取.bin 文件?我的 EA 创建的文件 notepad++ 无法读取,而且在 BT 期间,calendar.Load 什么也不返回。您对此有什么提示吗?

谢谢
 
eepatk #:
请问 notepad++ 能否读取.bin 文件?我的 EA 创建的文件不能被 notepad++ 读取,而且在 BT 期间,calendar.Load 什么也不返回。您对此有什么提示吗?

最好立即制定任务是什么。

 
fxsaber # :

最好立即制定任务是什么。

对不起 fxsaber,请允许我澄清一下。

基本上,我从您分享的示例代码开始,能够下载并创建 .bin 文件。

我正试图为 Backtest 编写以下代码,目的是在每次迭代时加载 .bin 文件,以便检查类中列出的每种货币的新闻/事件。

但是,当我进行回溯测试时,Calendar.ToString 返回空白("打印 "用于调试)。


谢谢、

 if ( MQLInfoInteger ( MQL_TESTER )) 
 {
    NF_Stopped_CCY="";  
      for(int i=0;i<8;i++)        
        {
                Calendar.Load(CALENDAR_FILENAME);
                Print("Raw",Calendar.ToString(0,10,false));  

                Calendar.FilterByTime(TimeCurrent()-NF_Stop_in_Days*24*60*60,TimeCurrent()+NF_Stop_in_Days*24*60*60);
                Print("FilterByTime",Calendar.ToString(0,10,false));  

                Calendar.FilterByCurrency(CCYP[i].Cname);
                Print("FilterByCCY",Calendar.ToString(0,10,false));  

                Calendar.FilterByImportance(NF_Stop_Importance);  
                Print("FilterByImp",Calendar.ToString(0,10,false));  
 
                          
                CCYP[i].Stop_By_News=Calendar.GetAmount();
                if (CCYP[i].Stop_By_News) 
                {
                  int temp=StringConcatenate(NF_Stopped_CCY,NF_Stopped_CCY," ", CCYP[i].Cname);
                  Print(Calendar.ToString(0,-1,false));  
                }
        } 
   Print("NF list(BackTest)   :",NF_Stopped_CCY);
   NEWS_RefreshTime.day =CurrentDay.day;
  }
 
eepatk #:

我正在尝试为 Backtest 编写以下代码,目的是在每次迭代时加载 .bin,以便检查类中列出的每种货币的新闻/事件。

您只需将文件中的数据加载到静态变量中一次。

#define  CALENDAR_FILENAME "Calendar.bin" // 读/写日历的文件名。
#property tester_file CALENDAR_FILENAME  // 指定 MT5-Tester 提取此文件。

#include <fxsaber\Calendar\Calendar.mqh> //https://www.mql5.com/zh/code/32430

CALENDAR CalendarFull; // 包含日历数据的对象。

int OnInit()
{      
  return(CalendarFull.Load(CALENDAR_FILENAME) == -1); // 从文件中加载事件
}

void OnTick()
{
  CALENDAR Calendar = CalendarFull;
  
  //....
}
 
fxsaber # :

您只需将文件中的数据加载到静态变量中一次。


非常感谢,它既漂亮又精确。

 
fxsaber # :

您只需将文件中的数据加载到静态变量中一次。

谢谢 fxaber、

我按照您的建议整理了代码,但加载 .bin 后 CalendarFULL 还是空的。

CalendarFULL.Load 的确返回了 "1",但 CalendarFULL 内似乎什么都没有。

这会不会是 .bin 的编码问题?

谢谢

 
eepatk #:

CalendarFULL.Load 返回的确实是 "1",但 CalendarFULL 内部似乎什么都没有。

在 MT5 端口运行此脚本一次,生成 bin 文件。

#define  CALENDAR_FILENAME "Calendar.bin" // 读/写日历的文件名。

#include <fxsaber\Calendar\Calendar.mqh> //https://www.mql5.com/zh/code/32430

void OnStart()
{
  CALENDAR Calendar;

  if (Calendar.Set(NULL, CALENDAR_IMPORTANCE_NONE, 0, 0)) // 从 MT5 终端加载所有事件(历史+未来)。
    Calendar.Save(CALENDAR_FILENAME);                     // 将它们保存到文件中。
}
 
fxsaber # :

在 MT5 端口运行此脚本一次,生成 bin 文件。

谢谢 fxsaber,我照做了,确实生成了一个 7xmb .bin 文件。但是,一旦我尝试加载并打印出来,它仍然返回空白。
 
eepatk #:
谢谢 fxsaber,我照做了,确实生成了一个 7xmb .bin 文件。但是,一旦我尝试加载和打印,它仍然返回空白。
#define  CALENDAR_FILENAME "Calendar.bin" // 读/写日历的文件名。
#property tester_file CALENDAR_FILENAME  // 指定 MT5-Tester 提取此文件。

#include <fxsaber\Calendar\Calendar.mqh> //https://www.mql5.com/zh/code/32430

const string inSymbols[] = {"EURUSD", "AUDCAD"};

CALENDAR Calendars[];

int OnInit()
{      
  CALENDAR Calendar;
  const bool Res = (Calendar.Load(CALENDAR_FILENAME) != -1);

  if (Res)
    for (int i = ArrayResize(Calendars, ArraySize(inSymbols)) - 1; i >= 0; i--)
    {
      Calendars[i] = Calendar;
      
      Calendars[i].FilterBySymbol(inSymbols[i]);
    }

  return(!Res);
}

string NewsToString( const CALENDAR &Calendar, const datetime From, const datetime To )
{
  CALENDAR CalendarTmp = Calendar;
  
  CalendarTmp.FilterByTime(From, To);
  
  return(CalendarTmp.ToString(0, 10));
}

#define  HALF_INTERVAL (6 * 3600)

void OnTick()
{  
  string Str = NULL;
  
  for (int i = ArraySize(Calendars) - 1; i >= 0; i--)
  {
    const datetime From = TimeCurrent() - HALF_INTERVAL;
    const datetime To = TimeCurrent() + HALF_INTERVAL;
    
    Str += "\n\n" + inSymbols[i] + "-news (" + (string)From + " - " + (string)To + "):\n" + NewsToString(Calendars[i], From, To);
  }
  
  Comment(Str);
}

 
fxsaber #:

谢谢 fxsaber、

最后,我找到了代码的问题所在,我的 .mq5 不知何故被保存为 Unicode 格式,这导致文件读取无法正常工作,而一旦我将其更改为 ANSI 格式,它就能正常工作了。


谢谢、