Multicurrency expert test results

 

Having read the articles on the construction of multi-currency EAs, asking questions and getting answers from the "gatekeepers" of the community, for me the question remains: "How to compose the EA code in such a way that the test results are correct?" The aim of the topic is just to find out this question.

I tested it using three different methods suggested by community members.

-OnTick().

-OnChartEvent(). This method is suggested by Konstantin Gruzdev in his article"Implementation of the Multicurrency Mode in MetaTrader 5".

-OnTimer().

I borrowed the scheme of multicurrency Expert Advisor from Nikolay Kositsin, which he described in details in his article"Creating an Expert Advisor that trades on different symbols".

For the test I wrote a simple EA because the essence is in comparing test results. The "reference" will be the result from the EURUSD daily chart since 2000. Then this result with the same parameters will be compared to the result that was obtained from the GBPUSD chart. In principle there is only one instrument involved in the tests, but the results should be identical regardless of which instrument is being tested.

OnTick()

int OnInit()
{
 return(0);
}

void OnDeinit()
{
}

void OnTick()
{  
 // Объявление массивов переменных для торговых сигналов
 static datetime New_Bar[1];  
 static bool UpSignal[1], DnSignal[1];
   
 // Получение торговых сигналов
 TradeSignalCounter(0,Symbol_01,Trade_01,Timeframe_01,UpSignal,DnSignal,New_Bar);

 // Совершение торговых операций
 TradePerformer(0,Symbol_01,Trade_01,Timeframe_01,Stop_Loss_01,Take_Profit_01,Slippage_01,UpSignal,DnSignal,New_Bar);
}

A test on EURUSD from the EURUSD chart:

Label: 01_tick

A test on EURUSD from GBPUSD chart:

Label:02_tick

The results of the test are not consistent.

OnChartEvent()

enum ENUM_CHART_EVENT_SYMBOL
  {
   CHARTEVENT_NO        =0,          // События отключены
   CHARTEVENT_INIT      =0,          // Событие "инициализация" 
   
   CHARTEVENT_NEWBAR_M1 =0x00000001, // Событие "новый бар" на 1 -минутном графике
   CHARTEVENT_NEWBAR_M2 =0x00000002, // Событие "новый бар" на 2 -минутном графике
   CHARTEVENT_NEWBAR_M3 =0x00000004, // Событие "новый бар" на 3 -минутном графике
   CHARTEVENT_NEWBAR_M4 =0x00000008, // Событие "новый бар" на 4 -минутном графике
   
   CHARTEVENT_NEWBAR_M5 =0x00000010, // Событие "новый бар" на 5 -минутном графике
   CHARTEVENT_NEWBAR_M6 =0x00000020, // Событие "новый бар" на 6 -минутном графике
   CHARTEVENT_NEWBAR_M10=0x00000040, // Событие "новый бар" на 10-минутном графике
   CHARTEVENT_NEWBAR_M12=0x00000080, // Событие "новый бар" на 12-минутном графике
   
   CHARTEVENT_NEWBAR_M15=0x00000100, // Событие "новый бар" на 15-минутном графике
   CHARTEVENT_NEWBAR_M20=0x00000200, // Событие "новый бар" на 20-минутном графике
   CHARTEVENT_NEWBAR_M30=0x00000400, // Событие "новый бар" на 30-минутном графике
   CHARTEVENT_NEWBAR_H1 =0x00000800, // Событие "новый бар" на 1 -часовом графике
   
   CHARTEVENT_NEWBAR_H2 =0x00001000, // Событие "новый бар" на 2 -часовом графике
   CHARTEVENT_NEWBAR_H3 =0x00002000, // Событие "новый бар" на 3 -часовом графике
   CHARTEVENT_NEWBAR_H4 =0x00004000, // Событие "новый бар" на 4 -часовом графике
   CHARTEVENT_NEWBAR_H6 =0x00008000, // Событие "новый бар" на 6 -часовом графике
   
   CHARTEVENT_NEWBAR_H8 =0x00010000, // Событие "новый бар" на 8 -часовом графике
   CHARTEVENT_NEWBAR_H12=0x00020000, // Событие "новый бар" на 12-часовом графике
   CHARTEVENT_NEWBAR_D1 =0x00040000, // Событие "новый бар" на дневном графике
   CHARTEVENT_NEWBAR_W1 =0x00080000, // Событие "новый бар" на недельном графике
     
   CHARTEVENT_NEWBAR_MN1=0x00100000, // Событие "новый бар" на месячном графике   
   CHARTEVENT_TICK      =0x00200000, // Событие "новый тик"
   
   CHARTEVENT_ALL       =0xFFFFFFFF, // Все события включены
  };

...

int OnInit()
{
 if(iCustom("EURUSD",PERIOD_D1,"Spy Control panel MCM",ChartID(),0,CHARTEVENT_TICK) == INVALID_HANDLE)
   { Print("Ошибка установки шпиона на EURUSD"); return(true);}
   
 if(iCustom("GBPUSD",PERIOD_D1,"Spy Control panel MCM",ChartID(),1,CHARTEVENT_TICK) == INVALID_HANDLE)
   { Print("Ошибка установки шпиона на GBPUSD"); return(true);}
}

void OnDeinit()
{
}

void OnChartEvent(const int id,         // идентификатор события
                  const long&   lparam, // флаг события поступившего от агента панели.
                                        // Флаги соответствуют перечислению ENUM_CHART_EVENT_SYMBOL.
                  const double& dparam, // цена
                  const string& sparam  // инструмент 
                 )
{
 if(id >= CHARTEVENT_CUSTOM)      
   {
    // Объявление массивов переменных для торговых сигналов
    static datetime New_Bar[1];  
    static bool UpSignal[1], DnSignal[1];
      
    // Получение торговых сигналов
    TradeSignalCounter(0,Symbol_01,Trade_01,Timeframe_01,UpSignal,DnSignal,New_Bar);
   
    // Совершение торговых операций
    TradePerformer(0,Symbol_01,Trade_01,Timeframe_01,Stop_Loss_01,Take_Profit_01,Slippage_01,UpSignal,DnSignal,New_Bar);
   }
}

Test on EURUSD from EURUSD chart:

Label:01_event == 01_tick

The result is identical to the result marked as 01_tick.

Test on EURUSD from GBPUSD chart:

Label:02_event ~= 02_tick

The test results are not consistent.

OnTimer()

int OnInit()
{
 EventSetTimer(10);

 return(0);
}

void OnDeinit()
{
 EventKillTimer();
}

void OnTimer()
{
 // Объявление массивов переменных для торговых сигналов
 static datetime New_Bar[1];  
 static bool UpSignal[1], DnSignal[1];
   
 // Получение торговых сигналов
 TradeSignalCounter(0,Symbol_01,Trade_01,Timeframe_01,UpSignal,DnSignal,New_Bar);

 // Совершение торговых операций
 TradePerformer(0,Symbol_01,Trade_01,Timeframe_01,Stop_Loss_01,Take_Profit_01,Slippage_01,UpSignal,DnSignal,New_Bar);
}

The timer is set to 10 seconds.

Test on EURUSD instrument from EURUSD chart:

Label: 01_time == 01_tick && 01_time == 01_ event

A test on EURUSD from GBPUSD chart:

Label: 02_time == 01_tick && 02_time == 01_ event

The test results are identical. Only in one place did I see a small inaccuracy. I also noticed that the smaller the interval in the timer, the more accurate the result. That is, even if the test is conducted on daily bars and the interval in the tester is set to, for example, 1 hour, the test will run significantly faster than 10 seconds, but the test results will not match.

------

That's all. Interested in everyone's opinion and even more interesting in the solution methods.)))


 

In my opinion, it is not correct to compare these options separately.

I personally adhere to the opinion that the timer in the cartoon must be, and what will be added to it (ticks or events) is a separate issue.

In my opinion, all available handlers should be used, the question is only in their filling and implementation of the general algorithm.

 
tol64:

"How do you put together the examiner code so that the test results are correct?".

I did not initially understand the statement of the question. What do you mean by "correct" test results, and why should they be achieved?
 
Interesting:

In my opinion, it is not correct to compare these options separately.

Personally, I'm of the opinion that the timer in the cartoon must be present, and what will be added to it (ticks or events) is a separate question.

The idea is that all available handlers should be used in the mule, it is only a question of their stuffing and implementation of the general algorithm.


Why is it incorrect to compare these options? Within the limits of a simple Expert Advisor when the decision is made after the bar is formed at the necessary symbol and the necessary TF, I think it is correct.

Incorrect as it is mentioned below, would be if we add a more complex algorithm for analyzing the current situation using the same ticks. But I am only interested in the formed bars.

 
Yedelkin:
Initially I did not understand the formulation of the question. What do you mean by "correct" test results, and why should they be achieved?

That is, the ones that correspond to reality. Whichever character we test from, the results should be identical. In this case, the identical result was achieved only by using the OnTimer() function.

I am very interested in Konstantin Gruzdev's method. Maybe I'm doing something wrong, that's why I didn't get the correct (reliable) results. I also hope for his comments on this subject.

 
tol64:

Why is it incorrect to compare these options? Within the framework of this simple Expert Advisor, when the decision is made after the bar is formed at the right symbol and the right TF, I think it is correct.

Incorrect, as it is mentioned below, would be if we add a more complex algorithm for analyzing the current situation using the same ticks. But I'm only interested in formed bars.

I don't argue, it is correct in theory, but in practice there are a lot of questions.

For example, here is the following one - it is implemented in the handler of ticks and the connection with the server is lost. How will the system work and how will it detect if something goes wrong?

Realization only in timer - More or less acceptable option, but it needs a reasonable compromise in the choice of period (but even then there will be some difficulties).

Events - The events themselves are not very efficient either. Generally speaking, the processing of ticks and events should be implemented in such a way as to use resources most effectively and allow the Expert Advisor to switch to processing a new portion of data rather quickly.

Yedelkin:
I did not understand the question from the beginning. What is the meaning of "correct" test results, and why they should be obtained?

I also think that you shouldn't achieve 100% identical results. Moreover, it is strange to limit the multiplying possibilities to ONE symbol trading.

Let's say at least two symbols will be traded (one of which could possibly be a chart symbol).

 
tol64:

That is, the ones that correspond to reality. Whichever symbol we test from, the results should be identical.

Believe me, finding 100% non-identity is self-deception and illusion. Just as illusion as an eternally working GRAAL. You have to always consider a certain margin of error/non-identity.

And as it is, testing a cartoon is not very revealing. The discussion about mults should only be in terms of trading on multiple symbols or trading with multiple strategies on one symbol.

I mean the PROSTANTLY identical results are not important in a multisymbol, but the mechanisms which allow expert making trade decisions taking into account positions and history.

For example, try to trade two symbols EURUSD and GBPUSD, while trading should be performed using hedging and signals on the second symbol.

 
Interesting:

Believe me, the search for 100% non-identity is a self-deception and an illusion. Just as illusion as the ever-working GRAAL. You always have to consider a certain margin of error/non-identity.

And as it is, testing a cartoon is not very revealing. The discussion about mults should only be in terms of trading on multiple symbols or trading with multiple strategies on one symbol.

I mean the PROSTANTLY identical results are not important in a multisymbol, the important mechanisms which allow expert to make trade decisions taking into account positions and history.

For example, try to trade two symbols EURUSD and GBPUSD, while trading should be performed using hedging and signals on the second symbol.

Now you are looking at the big picture, how the EA should work. Let's skip all the difficulties and technical details of the program implementation for real trading. The matter is very critical in this article.

1. A simple trading system. It is based on the formed bars.

2. A test on one symbol, but from another symbol.

I intentionally simplified the structure to the minimum. It is done to make it easier to analyze the test results. You can test all the symbols but the results will not become any better. You will get a mess that will be harder and longer to analyze. The Expert Advisor will show the exact action on the symbol it is located on, but it will make a mess on all the others, which is exactly what these results show. Test results should be identical, otherwise it turns out that the Expert Advisor makes correct entries on one symbol, while on the others it does not, or does not exactly follow the system. This discrepancy is quite noticeable.

So far, the identity can be achieved only through the OnTimer() function.

P.S. I don't believe in GRAILS. Or rather, I understand it differently than many others.)

 

Here is the result at once on five characters via the OnTimer() function:

Whichever symbol the test is performed from, the result is always the same.

But when using other methods(OnTick() and OnChartEvent()), the results would be different when changing the symbol where the Expert Advisor is located. And it just confirms that the Expert Advisor performs incorrect actions on other symbols.

It is clear why it happens with OnTick(). It has already been discussed many times. But the OnChartEvent() method is still questionable.

 

tol64:

With OnTick(), it's clear why this happens. This has already been discussed many times. But the OnChartEvent() method is still questionable.

We need to take into account a possible delay in event handling, or even possible LOSS of the event.
Документация по MQL5: Основы языка / Функции / Функции обработки событий
Документация по MQL5: Основы языка / Функции / Функции обработки событий
  • www.mql5.com
Основы языка / Функции / Функции обработки событий - Документация по MQL5
 
tol64:

That is, the ones that correspond to reality. Whichever character we test from, the results should be identical. In this case, the identical result was achieved only when OnTimer() was used.

I see it roughly. In fact, you are choosing an "engine" on which you are going to build your multi-currency Expert Advisor. For this, you take a primitive trading strategy and first you execute it according to the scheme "the signal source and signal handler on one symbol", and then according to the scheme "the signal source and signal handler on different symbols". Is this correct?

If so, I do not quite understand phrases like "Test on EURUSD tool from GBPUSD chart". Which symbol in this case is the signal source, and which one is the signal handler attached to?

Reason: