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

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

Manage alerts

Loading saved threads...

hamed razi · External communityPost link
External question — Stack Overflow Stack Exchange Author: hamed razi Original post: https://stackoverflow.com/questions/64640814 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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. 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); }
Quote
Report
user3666197 · External communityPost link
External answer — Stack Overflow Stack Exchange Author: user3666197 Original post: https://stackoverflow.com/a/64667855 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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. 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)
Quote
Report
Enivid · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Enivid Original post: https://stackoverflow.com/a/65040244 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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: 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.
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: user3666197 Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/64667855 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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. 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)

Cancel quote

Checking account access…