Tick Value returns inconsistent value in strategy tester?

 

Hi all, 

I'm calculating breakeven level in my ea that would take into account swaps and commissions - and I noticed that it doesn't seem to be consistent on a pair where my account currency is Term, i.e for the USD account USDJPY, USDCHF and USDCAD breakeven levels are constantly "dancing"


I reviewed the code again and again and the only reason I could deduce is that tester uses different TickValue for profit calculation compared to the one I get via MarketInfo(Symbol, MODE_TICKVALUE)


To verify that assumption I stuck this simple method in my EA:

void CheckProfit() {
   double tickValue = MarketInfo(_Symbol, MODE_TICKVALUE);
   double tickSize = MarketInfo(_Symbol, MODE_TICKSIZE);
   for(int i = OrdersTotal() - 1; i >= 0; i--){
      if(!OrderSelect(i, SELECT_BY_POS) || OrderSymbol() != _Symbol || OrderMagicNumber() != MagicNumber || OrderType() > OP_SELL)
         continue;
      int sign = OrderType() == OP_BUY ? 1 : -1;
      double profitEstimate = sign * (OrderClosePrice() - OrderOpenPrice()) / tickSize * tickValue * OrderLots();
      if(MathAbs(profitEstimate - OrderProfit()) > 0.009)
         Print("ALERT! inconsistent profit detected: estimate = ", DoubleToStr(profitEstimate, 4), ", actual=", OrderProfit());
   }
}

As I expected, started getting these alerts for, say, USDJPY:

2020.03.30 13:03:13.242 2020.01.03 11:42:13  Helper_v.3.1.4 USDJPY,M15: ALERT! inconsistent profit detected: estimate = 13.0080, actual=12.96

2020.03.30 13:03:13.242 2020.01.03 11:42:14  Helper_v.3.1.4 USDJPY,M15: ALERT! inconsistent profit detected: estimate = 13.4726, actual=13.42

I believe, tickValue never changes through the test run (at least the values I manually check seemed identical) while it should, I guess?


Did anyone face the issue before and is there a solution?

 

Quite amazingly, if I start calculating TickValue from the profit of an open trade to its lot and ticks difference it had traveled - it helps to solve the problem.

Essentially, I seem to be forced to calculate the value of the tick MT uses internally in tester, which is one ugly workaround - there are calculations like that all over my code.

If anyone has better solution, would be very much appreciated

 
rigal: I believe, tickValue never changes through the test run (at least the values I manually check seemed identical) while it should, I guess?
  1. Correct. Value depends on conversion rates (base, quote, and account currencies) and the tester uses a constant for the entire run.
    But the can occur some inaccuracies in estimation of margin requirements on cross currencies because of lack of precise information about conversion prices at each moment.
              'Testing Features and Limits in MetaTrader 4' - MQL4 Articles 2012

  2. Instant Execution mode is assumed to be used in trades, being processed without slippage Processing orders, Open/Close without slippages
              'Testing Features and Limits in MetaTrader 4' - MQL4 Articles 2012
    Unless you are holding trades over many months, you're in the noise, ignore it. The error do to no slippage modeled will far greater than what you are looking at.
 
William Roeder:
  1. Correct. Value depends on conversion rates (base, quote, and account currencies) and the tester uses a constant for the entire run.

  2. Unless you are holding trades over many months, you're in the noise, ignore it. The error do to no slippage modeled will far greater than what you are looking at.

Hi @William Roeder, thanks for your reply.

What bugs me here is that, while the value I'm getting via MarketInfo("USDJPY", MODE_TICKVALUE) is indeed constant through the run, tester itself seems to account for the rate changes

Provided my account is in one of the currencies in a traded pair, the calculation is somewhat trivial so I'm not surprised tester is doing the math.

Would be really nice to have that value returned via MarketInfo though - otherwise whatever calculations EA is doing won't match those of the tester resulting in many possible discrepancies in the run.

Can't get it why did they make it use one value for profit calculation internally and return different one.

I only wish for consistency here, not enhancing the actual rate interpolation

Reason: