In MT5, the NewTick event only occurs on the symbol on which the EA is running. Therefore, various tricks are used for multisymbol trading.

This library creates a multisymbol OnTick on all specified trading symbols. A convenient wrapper of the old implementation.

Example.

Let's show the work of the library on the example of a multisymbol Expert Advisor that counts the number of incoming ticks for each specified symbol.

#include <fxsaber\OnTickMulti\OnTickMulti.mqh> // Multisymbol OnTick.

int TicksCounter[]; // The counter of incoming ticks of each given character.

void OnInit()
{
  // Initialise the counter of incoming ticks.
  ArrayResize(TicksCounter, ArraySize(OnTickMultiObject.Symbols));
  ArrayInitialize(TicksCounter, 0);
}

double OnTester()
{
  // Print the number of arrived ticks for each given character.
  for (uint i = ArraySize(TicksCounter); (bool)i--;)
    Print(OnTickMultiObject.Symbols[i] + " - " + (string)TicksCounter[i] + " ticks.");

  ArrayPrint(OnTickMultiObject.Symbols); // List of symbols OnTickMulti.

  return(0);
}

// Multisymbol OnTick.
void OnTickMulti( const string &Symb, const uint &Index )
{
  TicksCounter[Index]++; // Increased the counter of incoming ticks by the given symbol.
}

Result.

To check the correctness of the Expert Advisor, let's run it in MT5-tester.

After comma in the input we set the symbols to which the multisymbol OnTick will react.

The tester produced the following (see the Log).

2023.01.12 23:59:59   AUDJPY - 1618389 ticks.
2023.01.12 23:59:59   GBPUSD - 1116822 ticks.
2023.01.12 23:59:59   EURUSD - 906489 ticks.
2023.01.12 23:59:59   "EURUSD" "GBPUSD" "AUDJPY"
final balance 10000.00 pips
OnTester result 0
EURUSD,M1: 906489 ticks, 12897 bars generated. Environment synchronized in 0:00:00.020. Test passed in 0:00:01.723 (including ticks preprocessing 0:00:00.188).
EURUSD,M1: total time from login to stop testing 0:00:01.743 (including 0:00:00.248 for history data synchronization)
3641700 total ticks for all symbols
AUDJPY: generate 1618389 ticks in 0:00:00.078, passed to tester 1618389 ticks
EURUSD: generate 906489 ticks in 0:00:00.047, passed to tester 906489 ticks
GBPUSD: generate 1116822 ticks in 0:00:00.063, passed to tester 1116822 ticks

The highlighted part shows that absolutely all the ticks generated by the Tester for the specified symbols were processed by the multisymbol OnTick.

What for?

  • With this library, the result of the Expert Advisor's work in the Tester may not depend on the selected basic symbol.
  • Ticks on the required symbols are not skipped.