Bug: currency set in Settings form of Strategy Tester window not propagated to TesterInit event

 

I think I found a bug, or at least a strange behavior, occurring when I choose to use in the Settings form of the Strategy Tester window a currency different from my account currency.


I have an EUR account, and if I choose to use USD as currency in the Strategy Tester, I see that this information is correctly propagated to my EA's OnInit() function but not to the OnTesterInit() event handler. It seems that the optimizer is not aware of this setting.


The following very simple code can be used to reproduce this behavior. If I perform a single execution of the EA, I can see that USD is correctly printed in the Journal, instead if a run an optimization, I see EUR printed.


input int fake_input = 1;

int OnInit()
{
  Print("T Account currency: ", AccountInfoString(ACCOUNT_CURRENCY));

  return INIT_FAILED;
}

int OnTesterInit()
{
  Print("O Account currency: ", AccountInfoString(ACCOUNT_CURRENCY));

  return INIT_FAILED;
}

void OnTesterDeinit()
{ }


 As I said, I have an EUR account but would like to use USD currency to optimize all EAs operating on USD-based symbols, and would like to open a message box in the OnTesterInit() function if this condition is not met. At the moment, I cannot perform this check in the OnTesterInit() function.

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
 
  1. Open a USD demo account with MQ or your broker and do your tests
  2. use points (pips) instead of money to speed up the tester:

 
Carl Schreiber #:
  1. Open a USD demo account with MQ or your broker and do your tests
  2. use points (pips) instead of money to speed up the tester:

I don't want to open a USD demo account: I have a EUR account that works perfectly also if I choose to use USD as currency for my tests and optimizations, all the profits are perfectly calculated etc. The only thing is that, if I choose to use USD as currency for my optimization, the optimizer 'thinks' that the currency is always EUR. So I think this is a bug of MT5.

The tester in single mode correctly 'understands' that the currency is USD, only these functions of the optimizer are apparently not aware of this: OnTesterInit() and OnTesterDeinit(). Please try the code above to see what I mean.

 
f.pap #:

I don't want to open a USD demo account: I have a EUR account that works perfectly also if I choose to use USD as currency for my tests and optimizations, all the profits are perfectly calculated etc. The only thing is that, if I choose to use USD as currency for my optimization, the optimizer 'thinks' that the currency is always EUR. So I think this is a bug of MT5.

The tester in single mode correctly 'understands' that the currency is USD, only these functions of the optimizer are apparently not aware of this: OnTesterInit() and OnTesterDeinit(). Please try the code above to see what I mean.

You are wrong as you are mixing Symbol and account currency. The account with its currency is needed for all the trade settings set by the broker and for a symbol you choose for trading you have this condition:


(See https://www.mql5.com/en/articles/1453)

So if you have e.g. a USD account the trading result of EURGBP is in GBP which has to be converted in USD of your account. Therefore the tester offers the calc. on pips or points to save the  loading and converting the additional exchange rates.

Forex Trading ABC
Forex Trading ABC
  • www.mql5.com
Working on financial markets represents, first of all, trade operations. We all, starting from the very childhood, have an intuitive idea of what is to buy and to sell. But Forex trading is still something special. This article deals with the ideas necessary to explain some terms. We will also consider the MQL 4 functions that correspond with those terms.
 
f.pap:

I think I found a bug, or at least a strange behavior, occurring when I choose to use in the Settings form of the Strategy Tester window a currency different from my account currency.


I have an EUR account, and if I choose to use USD as currency in the Strategy Tester, I see that this information is correctly propagated to my EA's OnInit() function but not to the OnTesterInit() event handler. It seems that the optimizer is not aware of this setting.


The following very simple code can be used to reproduce this behavior. If I perform a single execution of the EA, I can see that USD is correctly printed in the Journal, instead if a run an optimization, I see EUR printed.


input int fake_input = 1;

int OnInit()
{
  Print("T Account currency: ", AccountInfoString(ACCOUNT_CURRENCY));

  return INIT_FAILED;
}

int OnTesterInit()
{
  Print("O Account currency: ", AccountInfoString(ACCOUNT_CURRENCY));

  return INIT_FAILED;
}

void OnTesterDeinit()
{ }


 As I said, I have an EUR account but would like to use USD currency to optimize all EAs operating on USD-based symbols, and would like to open a message box in the OnTesterInit() function if this condition is not met. At the moment, I cannot perform this check in the OnTesterInit() function.

The OnTesterInit() function and the likes are running on a live chart, not in the Tester. They are done to work with optimization passes results, there is no point to use AccountInfoxxx() functions there.
 
Alain Verleyen #:
The OnTesterInit() function and the likes are running on a live chart, not in the Tester. They are done to work with optimization passes results, there is no point to use AccountInfoxxx() functions there.

Yes, you're right because also AccountInfoDouble(ACCOUNT_BALANCE) for example returns different values in the OnInit() function (the deposit amount set in the Settings) and in the OnTesterInit() function (the real account balance).

This behavior appears strange to me because, at least from what I understand, the OnTesterInit() function is used for preparing an optimization, that is, multiple runs of the EA with different values for the inputs being optimized. These runs of the EA 'see' some account parameters (the 'fake' ones, set in the Setting and being simulated as parameters of a fake account), the OnTesterInit() function, immediately before starting optimization, 'sees' other account parameters (the ones of the real account).

Is there any other way to retrieve the deposit currency set in the Settings before optimization starts?

Reason: