简体   繁体   English

如何从策略测试器 (MT4) 中的周期设置以外的时间范围获取数据

[英]How can I get data from a time frame other than period setting in strategy tester (MT4)

I want to know How can I get data from a time frame other than period setting in Strategy Tester (a part of MetaTrader4 Trading Terminal), using the sample code below, I get zero results for op2 & EMA2 whenever I choose a period setting other than M5 in the Strategy Tester.我想知道如何从策略测试程序(MetaTrader4 交易终端的一部分)中的时间段设置以外的时间范围获取数据,使用下面的示例代码,每当我选择其他时间段设置时, op2EMA2结果为零比策略测试器中的M5

How can I fix it?我该如何解决?

  void OnTick()
  {  
       string print = "\n\n\n\n\n\n" +
                      "\n op1= "   + iOpen(NULL,PERIOD_CURRENT,0) +
                      "\n op2= "   + iOpen(NULL,PERIOD_M5,0) +
                      "\n EMA1 : " +   iMA(NULL,PERIOD_CURRENT,21,0,MODE_EMA,PRICE_CLOSE,0) +
                      "\n EMA2 : " +   iMA(NULL,PERIOD_M5,21,0,MODE_EMA,PRICE_CLOSE,0);
    
       Comment(print);        
  }

在此处输入图片说明

Q : "How can I fix it?"“我该如何解决?”

Well,好,

for about the last 12+ years, this (otherwise properly crafted piece of syntax) has never worked correctly inside the MetaTrader Terminal 4 Strategy Tester.大约在过去的 12 年多以来,这个(以其他方式精心制作的语法)从未在 MetaTrader 终端 4 策略测试器中正常工作。

If in doubts here, one may try to re-run the very same piece of code inside an Expert Advisor or Script type-of-MQL4-code & you shall see no troubles there (sure, only in cases the FOREX Market QUOTE -message-feed is live & delivering QUOTE -tick FX market-events that trigger the EA- OnTick() -method ... for obvious reasons this is no problem for a Script type-of-MQL4-code)如果在这里有疑问,可以尝试在“EA 交易”或“脚本”类型的 MQL4 代码中重新运行完全相同的代码段,您不会在那里看到任何问题(当然,仅在 FOREX Market QUOTE消息的情况下) -feed 是实时的并提供QUOTE -tick FX 市场事件,触发 EA- OnTick() - 方法......出于显而易见的原因,这对于脚本类型的 MQL4 代码没有问题)

Actually, this can be fixed, but with one limitation - you can only request higher-timeframe data when running a backtest on a lower timeframe.实际上,这可以解决,但有一个限制 - 在较低的时间范围内运行回测时,您只能请求较高的时间范围数据。 For example, if you were to run a backtest on M5, this would return non-zero values:例如,如果您要在 M5 上运行回测,这将返回非零值:

  void OnTick()
  {  
       string print = "\n\n\n\n\n\n" +
                      "\n op1= "   + iOpen(NULL,PERIOD_CURRENT,0) +
                      "\n op2= "   + iOpen(NULL,PERIOD_M15,0) +
                      "\n EMA1 : " +   iMA(NULL,PERIOD_CURRENT,21,0,MODE_EMA,PRICE_CLOSE,0) +
                      "\n EMA2 : " +   iMA(NULL,PERIOD_M15,21,0,MODE_EMA,PRICE_CLOSE,0);
    
       Comment(print);        
  }

Luckily, it is often possible to rewrite the EA's logic in such a way as to work from lower timeframe with a higher timeframe for backtesting purposes.幸运的是,通常可以重写 EA 的逻辑,以便从较低的时间范围和较高的时间范围工作以进行回溯测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MT4 Strategy Tester回测结果面板日期是否与MT4 Graph相关联? - Are MT4 Strategy Tester backtest results panel dates somehow linked with MT4 Graph? MT4-PERIOD的 - MT4 - PERIOD 's 如何将数据从我的网站发送到 MT4 软件? - How do i send data from my website to MT4 software? 如何从vb.net实时从MetaTrader4终端(MT4)读取蜡烛数据 - How to read candle data from a MetaTrader4 Terminal ( MT4 ) from vb.net in realtime 如何将MT4中的文件夹结构粘贴到Tradingview中的文件夹结构中 - How can I paste my folder structure in my MT4 into a folder structure in Tradingview ZeroMQ 连接器仍然成功发送数据但未能从 MT4 服务器获得响应 - ZeroMQ Connector still sent data successfully but failed to get response from MT4 Server 如何自动重新调整当前图表上显示的价格范围? (MT4 EA) - How can I automatically rescale the price range shown on the current chart? (MT4 EA) 如何从现有的MT4指标代码导出到CSV文件 - How to export to a CSV file from an Existent MT4 Indicator code iCustom()缓冲区-如何从MT4中的自定义指标缓冲区获取值? - iCustom() buffer - how to get values from Custom Indicator buffers in MT4? 如何获得第 N 个未平仓头寸 MQL4 / MT4 的利润? - How to get a profit of Nth open position MQL4 / MT4?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM