Errors, bugs, questions - page 2222

 
Alexander:

Stable playback ? What build?

Yes, the problem is reproducible. Version 1870.
 

Question.

Suppose I work with several symbols in an Expert Advisor or indicator, or rather with all the symbols that are displayed in the Market Watch window.

The task is to catch the moment of a new tick on any of the symbols.

So far I see only a couple of options:
  1. Through a timer with polling of all symbols. (of course, you can only poll the new value ofTimeCurrent(), but in this case the error will be 1 second, because this function returns a value in seconds)
  2. at each symbol in OnTick (or OnCalculate) to generate a custom event through EventChartCustom

The disadvantage of the first option is non-optimality in terms of resources and data relevance. OnTimer will mainly hammer in idle, and when it catches a new quote, the arrival time error will be equal to the timer periodicity.

The disadvantage of the second variant is cumbersomeness, especially if there are dozens of symbols.

Do I understand correctly that there are no other options (simpler and more elegant)? Or (I hope) am I wrong?

 
Nikolai Semko:

Question.

Suppose I work with several symbols in an Expert Advisor or indicator, or rather with all the symbols that are displayed in the Market Watch window.

The task is to catch the moment of a new tick on any of the symbols.

I can only see a couple of options so far:
  1. Through a timer with polling of all symbols. (of course, you can only poll the new value ofTimeCurrent(), but in this case the error will be 1 second, because this function returns a value in seconds)
  2. at each symbol in OnTick (or OnCalculate) to generate a custom event through EventChartCustom

The disadvantage of the first option is non-optimality in terms of resources and data relevance. OnTimer will mainly hammer in idle, and when it catches a new quote, the arrival time error will be equal to the timer periodicity.

The disadvantage of the second variant is cumbersomeness, especially if there are dozens of symbols.

Do I understand correctly that there are no other options (simpler and more elegant)? Or (I hope) am I wrong?

Maybe this will help? https://www.metatrader5.com/ru/terminal/help/trading_advanced/custom_instruments

Synthetic instruments with real-time quotes

The trading platform allows you to create synthetic financial instruments - instruments based on one or more existing ones. You just need to set a formula to calculate the quotes and the platform will generate real-time ticks of the synthetic instrument as well as create its minute history.
How it works

You create a synthetic instrument and set the formula for it.
The platform will calculate its ticks with a frequency of 10 times per second (and only if the price of at least one instrument in the formula changes).
 
SEM:

Maybe this will help? https://www.metatrader5.com/ru/terminal/help/trading_advanced/custom_instruments

Synthetic instruments with real-time quotes

The trading platform allows you to create synthetic financial instruments - instruments based on one or more existing ones. All you need to do is specify the formula for calculating the quotes and the platform will generate the ticks of the synthetic instrument in real time and create its minute history.
How it works

You create a synthetic instrument and set the formula for it.
The platform will calculate its ticks with a frequency of 10 times per second (and only if the price of at least one instrument in the formula has changed).

Yes, of course, that variant has a right to life too. Thanks!
But, in fact, it is the same as my variant #1 with timer periodicity of 100 ms and with the same disadvantages.

Option 2 seems more rational to me, though.

By the way, I remembered that option 2 has already been discussed here.


 
Nikolai Semko:

Yes, of course, this variant has a right to life, too. Thank you!
However, in essence, it is the same as the variant #1 above with timer period of 100 ms.

Wouldn't it be easier to make an EA linked to the symbol on which it is working. Then open all symbols and apply the template with this EA to each chart.

for(int i=PositionsTotal()-1;i>=0;i--)
     {
      if(PositionGetSymbol(i)==Symbol())
        {
         //Код
        };

     }
 
SEM:
Wouldn't it be easier to make an EA linked to the symbol on which it is working. Then open all symbols, and for each chart apply a template with this EA.

It is clear that this can be done. The matter is that I do not know something and it is possible to trace the exact moment of coming of the quote for another symbol through the code of only one multi-currency EA.
But it seems that variant 2 via custom interrupts is the only rational solution.

 
Nikolai Semko:

Yes, it is clear that it can be done that way. The question is that I don't know something, and it's possible to catch the exact moment of coming of the quote for another symbol through the code of only one multi-currency Expert Advisor.
But it seems that variant 2 via custom interrupts is the only rational solution.

Implementation.

Особенности языка mql5, тонкости и приёмы работы
Особенности языка mql5, тонкости и приёмы работы
  • 2018.01.28
  • www.mql5.com
В данной теме будут обсуждаться недокументированные приёмы работы с языком mql5, примеры решения тех, или иных задач...
 
Nikolai Semko:
  1. via timer with polling of all characters. (Of course, you could just poll the new value ofTimeCurrent(), but in this case the error would be 1 second, because this function returns a value in seconds).

Am I correct in assuming that there are no other options (simpler and more elegant)? Or (I hope) am I wrong?

Millisecond timer + SymbolInfoTick() will get the time in milliseconds.

 
Yes, I already gave this link to your implementation in post 22214. I'll say it again - I think this variant is the most reasonable so far. And it seems that there is no better implementation in terms of minimal CPU load and relevance of the resulting moment of a new tick.
 
Nikolai Semko:
  1. через таймер c опросом всех символов. (можно, конечно, только опрашивать новое значение функции TimeCurrent(), но в этом случае погрешность будет равна 1 секунде, т.к. эта функция возвращает значение в секундах)

Я правильно понимаю, что других вариантов (более простых и изящных) не существует? Или (надеюсь) я не прав?

Millisecond timer + SymbolInfoTick() get the time in milliseconds.

Alexey Kozitsyn:

Millisecond timer + SymbolInfoTick() get time in milliseconds.

It's variant 1. I meant such a construct (Millisecond timer + SymbolInfoTick() loop). I mentionedTimeCurrent() because it returns"the time of arrival of the last quote for any symbol available in Market Watch window", not only for the current symbol, but unfortunately it returns only seconds, which is very rude for ticks.
Objectively, the variant with user interrupts is more reasonable, because there is no need to organize a loop with the expensive SymbolInfoTick function constantly, even when the quotes are sleeping, thus loading the processor with idle time. In addition, the error of calculating a new tick may be equal to the periodicity of the timer, and all ticks will be lost between OnTimer execution, if such ticks were more than 1.
SZZ We are talking about mql5. On mql4 the user interruptions do not work properly. Therefore, the mql4 can only use the timer.