In the strategy tester there are many symbols that I cannot select or get information from in my expert advisor (EA). In fact, it seems as if there's a bug within MQL4 itself. I'm attempting to automatically buy and sell in my EA, and it's important that I'm able to get symbol info from other symbols to calculate the correct amount of lots I need. This doesn't seem to be possible inside the strategy tester.
The following EA provides different results when ran in the debugger vs a strategy tester (both using the GBPCAD chart).
int OnInit(){
if (!SymbolSelect("USDCAD", true))
Print("Couldn't select USDCAD");
if (SymbolInfoInteger("USDCAD", SYMBOL_VISIBLE))
Print("USDCAD visible");
else
Print("USDCAD isn't visible");
double e;
if (SymbolInfoDouble("USDCAD", SYMBOL_ASK, e))
Print("It worked");
else
Print("It didn't work, ", GetLastError());
return(INIT_SUCCEEDED);
}
On the debugger in live data, the following is printed:
2020.08.23 11:25:20.011 Exit Backtester GBPCAD,Daily: USDCAD visible
2020.08.23 11:25:20.011 Exit Backtester GBPCAD,Daily: It worked
On the strategy tester near the beginning of 2017, the following is printed:
2020.08.23 11:26:01.200 2017.02.09 00:00:00 Exit Backtester GBPCAD,Daily: Couldn't select USDCAD
2020.08.23 11:26:01.200 2017.02.09 00:00:00 Exit Backtester GBPCAD,Daily: USDCAD isn't visible
2020.08.23 11:26:01.200 2017.02.09 00:00:00 Exit Backtester GBPCAD,Daily: It didn't work, 4106
Where error code 4106, according to the documentation, states that the symbol is not selected in Market Watch or found in the list of "available ones".
However, running the following code:
void PrintSymbols(){
for (int i = 0; i < SymbolsTotal(true); ++i){
Print(i, " ", SymbolName(i, true));
}
}
int OnInit(){
PrintSymbols();
return(INIT_SUCCEEDED);
}
Prints the same results in both cases, among them being USDCAD:
2020.08.23 11:38:03.235 Exit Backtester GBPCAD,Daily: 18 USDCAD
So SymbolName proves that USDCAD is available, while SymbolSelect, SymbolInfoInteger, and SymbolInfoDouble prove otherwise.
Why is this the case?