[英]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 交易终端的一部分)中的时间段设置以外的时间范围获取数据,使用下面的示例代码,每当我选择其他时间段设置时, op2
和EMA2
结果为零比策略测试器中的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.