Strategy Tester not using enough historical data - MT4

 

Hello! I’ve been working on my EA for the past couple of months. Since I coded an option to test historical data as far back as I wanted, I never really needed to use the Strategy Tester. However, now that I’m preparing to run my EA on a demo account, I wanted to test it in the Strategy Tester as well. My EA works as follows:

1. It first analyzes historical data on a higher time frame (OnInit).

2. Based on this data, it looks for trade entries on a lower time frame.

The issue I encountered when using the Strategy Tester is that my EA barely accesses historical data. It seems to look back only about 14 days, while outside of the Strategy Tester, it correctly processes and marks points of interest for as many days as needed. This is not an issue of missing historical data - e.g. I can manually set the EA to analyze from Auguest 17, 2023, and since I have data going back several years on the higher time frame that needs to be checked, everything works fine. However, when I use the same day in the Strategy Tester, the data gathered is barely there. How can I make the Strategy Tester load and use several months of historical data before the selected test date? Is there a way to force it to load more bars? Any help would be greatly appreciated!

 
Łukasz: The issue I encountered when using the Strategy Tester is that my EA barely accesses historical data. It seems to look back only about 14 days,

Yes, that is correct. At the start of the test it only has access to about 1000 bars of the default time-frame.

In order to access more data, you have to set the testing period to much further back in time (sufficient for your testing needs), but you will also have to add an input to your code, to only start trading at a specific date further along the test period.

For example, your test period could be from 2018 to 2025, but you set your "trading start" input to start in 2021, so that it will have historical data all the way back to 2018, even though it only starts trading in 2021.

EDIT: Also remember to you have to synchronise your other time-frames and handle the 4066/4073 errors correctly (run a search here in the forum for more information).

 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
pagul: 1. It first analyzes historical data on a higher time frame (OnInit).

You should never access trade, symbol or quote/price data in the OnInit() handler. That should be used for a quick initialisation only.

During the OnInit there is no guarantee that the account is even connected or that data is available.

Instead, wait for the first tick to arrive in OnTick() and only then carry out your analysis.

 
Thank you very much for helping me! I'll deal with this shortly, as soon as I deal with error 130 :)