MT5 and speed in action - page 61

 
fxsaber:

I feel that this MQ wall will not get through without the support of the forum members. The code is short, the pros should be able to figure it out quickly. There are no flaws there. It is clearly shown that prices through positions are obtained much faster than from Market Watch. How MQ can't see the obvious - I don't understand.

1. Your test really counts a micro percentage of iterations due to the condition

if (Interval##A > 100)

In essence you only count anomalies where the processor is overloaded with tasks and put off performing the given task on the far shelf, as over 99% of iterations are performed in less than 1 microsecond.

And even if you set the condition >0, there is still no objectivity.

2. The time measurement of such fast operations should only be done as a full cycle time, not a single iteration.

3. But since the cycle in your example is limited to 10 seconds (Why! For ticks I think 0.1 sec is quite enough. Because it may well happen that 3 ticks will arrive in a second, and all the three ticks will be executed for 10 seconds each, and in parallel), so no timing is needed. It's easier to calculate how many iterations will be executed in a given time. The more, the more productivity.

I modified your code "a bit". I think my variant reflects reality better.

The calculation is done one at a time, so as not to mix the two variants. Even numbered ticks are forSYMBOL_BID, odd ones - for GetBid().

I added sums and their output just in case, as an attempt to trick the compiler against optimization.
The output result is cumulative.

#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

#define  Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)
#define  TimeLoop 125  // 15.625*8  

bool GetPosition(const int Type = OP_BUY)
  {
   bool Res = false;
   for(int i = PositionsTotal() - 1; (i >= 0) && !Res; i--)
      Res = PositionGetTicket(i) && (PositionGetInteger(POSITION_TYPE) == Type) &&
            (PositionGetString(POSITION_SYMBOL) == _Symbol);
   return(Res);
  }

// Альтернативный способ получения Bid-цены текущего символа.
// Запускать только на демо-счетах.
double GetBid()
  {
   static const TICKET_TYPE Ticket = GetPosition() ? PositionGetInteger(POSITION_TICKET) : OrderSend(_Symbol, OP_BUY, 0.1, Ask, 0, 0, 0);
   return(PositionSelectByTicket(Ticket) ? PositionGetDouble(POSITION_PRICE_CURRENT) : 0);
  }

#define  TOSTRING(A) ", "#A + " = " + (string)(A)


long N1=0;
long N2=0;
long n=0;
double sum1=0;
double sum2=0;

const bool Init = EventSetTimer(10) && GetBid(); // Будем выводить статистику каждый 10 секунд.

//+------------------------------------------------------------------+

void OnTick()
  {
//  return;
   const uint StartTime = GetTickCount();
   if(n%2==0)
      while(!IsStopped() && (GetTickCount() - StartTime < TimeLoop))
        {
         sum1+=SymbolInfoDouble(_Symbol, SYMBOL_BID);
         N1++;
        }
   else
      while(!IsStopped() && (GetTickCount() - StartTime < TimeLoop))
        {
         sum2+=GetBid();
         N2++;
        }
   if(n%2==0 && n>1)
      if (N1>N2) Print(_Symbol+": SYMBOL_BID быстрее GetBid() в " + DoubleToString(double(N1)/N2,2) + " раза. Среднее время одной итерации: SYMBOL_BID - " + DoubleToString((TimeLoop*1000000.0*n/2)/N1,2) + " ns, GetBid() - " + DoubleToString((TimeLoop*1000000.0*n/2)/N2,2) + " ns" + TOSTRING(sum1) + TOSTRING(sum2));
      else       Print(_Symbol+": GetBid() быстрее SYMBOL_BID в " + DoubleToString(double(N2)/N1,2) + " раза. Среднее время одной итерации: SYMBOL_BID - " + DoubleToString((TimeLoop*1000000.0*n/2)/N1,2) + " ns, GetBid() - " + DoubleToString((TimeLoop*1000000.0*n/2)/N2,2) + " ns" + TOSTRING(sum1) + TOSTRING(sum2));
      n++;
  }
//+------------------------------------------------------------------+

My result:

2020.10.26 19:26:46.193 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.97 раза. Среднее время одной итерации: SYMBOL_BID - 45.80 ns, GetBid() - 135.80 ns, sum1 = 106706334.7283292, sum2 = 35987491.50911281
2020.10.26 19:26:46.193 FxSaberBidSpeed (EURUSD,M1)     EURUSD: SYMBOL_BID быстрее GetBid() в 2.90 раза. Среднее время одной итерации: SYMBOL_BID - 45.10 ns, GetBid() - 130.82 ns, sum1 = 34042649.2788716,  sum2 = 11735304.45101236
2020.10.26 19:26:47.085 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.95 раза. Среднее время одной итерации: SYMBOL_BID - 45.57 ns, GetBid() - 134.55 ns, sum1 = 110131593.3516681, sum2 = 37303001.98488424
2020.10.26 19:26:52.397 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.99 раза. Среднее время одной итерации: SYMBOL_BID - 45.48 ns, GetBid() - 135.90 ns, sum1 = 113269505.1945728, sum2 = 37903458.6724181
2020.10.26 19:26:59.412 FxSaberBidSpeed (EURUSD,M1)     EURUSD: SYMBOL_BID быстрее GetBid() в 2.85 раза. Среднее время одной итерации: SYMBOL_BID - 45.16 ns, GetBid() - 128.57 ns, sum1 = 36611618.7279973,  sum2 = 12858907.51985167
2020.10.26 19:27:00.131 FxSaberBidSpeed (BTCUSD,M1)     BTCUSD: SYMBOL_BID быстрее GetBid() в 2.78 раза. Среднее время одной итерации: SYMBOL_BID - 47.10 ns, GetBid() - 130.88 ns, sum1 = 305215291120.0239, sum2 = 109832697267.1495
2020.10.26 19:27:03.303 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.96 раза. Среднее время одной итерации: SYMBOL_BID - 45.44 ns, GetBid() - 134.61 ns, sum1 = 116279675.0471961, sum2 = 39248002.75579567
2020.10.26 19:27:06.318 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 3.01 раза. Среднее время одной итерации: SYMBOL_BID - 45.17 ns, GetBid() - 135.96 ns, sum1 = 119877506.6663743, sum2 = 39829996.08171722
2020.10.26 19:27:06.709 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 3.01 раза. Среднее время одной итерации: SYMBOL_BID - 44.92 ns, GetBid() - 135.42 ns, sum1 = 123505976.1123297, sum2 = 40965170.16304104
2020.10.26 19:27:07.803 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.99 раза. Среднее время одной итерации: SYMBOL_BID - 44.84 ns, GetBid() - 134.00 ns, sum1 = 126664503.6443297, sum2 = 42385980.37108831
As you can see, the difference in performance is three times in favour of the standard version.
 
Nikolai Semko:


As you can see the difference in performance is three times in favour of the original version.

Does the original version from fxsaber show the GetBid advantage, or is it about a more powerful/less loaded PC?

 
Andrey Khatimlianskii:

Does the original version by fxsaber show GetBid advantage, or is it more powerful/less loaded PC?

His variant also showed GetBid advantage at full CPU load. But at the same time my variant shows three times the advantage of the regular function at the same load.
This
is because my variant takes into account the average time of all iterations of getting Bid price and its only a tiny fraction with anomalous hangs.
Who knows for what reason the processor gets bogged down with the regular function (when the delay is more than 100 µ) in a difficult "minute". But still the average time is three times less for the regular function

So, for example, if (Interval##A > 100) this is the case:

whereas if (Interval##A > 0) is already quite different, showing a random distribution of abnormal delays between the regular and the alternative version of getting the Bid price

at the same time my test at the same CPU load shows:

2020.10.26 22:16:10.569 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.79 раза. Среднее время одной итерации: SYMBOL_BID - 57.95 ns, GetBid() - 161.43 ns, sum1 = 108105265.450882, sum2 = 38804020.20301527
2020.10.26 22:16:12.146 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.79 раза. Среднее время одной итерации: SYMBOL_BID - 57.81 ns, GetBid() - 161.06 ns, sum1 = 111212159.8857315, sum2 = 39917412.88663763
2020.10.26 22:16:13.741 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.79 раза. Среднее время одной итерации: SYMBOL_BID - 57.37 ns, GetBid() - 159.91 ns, sum1 = 114942034.0034028, sum2 = 41233865.03452455
2020.10.26 22:16:14.740 FxSaberBidSpeed (EURUSD,M1)     EURUSD: SYMBOL_BID быстрее GetBid() в 3.18 раза. Среднее время одной итерации: SYMBOL_BID - 52.88 ns, GetBid() - 167.92 ns, sum1 = 75470423.51597476, sum2 = 23764764.64380601
2020.10.26 22:16:15.756 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.78 раза. Среднее время одной итерации: SYMBOL_BID - 57.30 ns, GetBid() - 159.06 ns, sum1 = 117956798.0483066, sum2 = 42491447.24894404
2020.10.26 22:16:17.646 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.77 раза. Среднее время одной итерации: SYMBOL_BID - 57.19 ns, GetBid() - 158.36 ns, sum1 = 121056970.4066543, sum2 = 43721243.0341278
2020.10.26 22:16:20.146 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.76 раза. Среднее время одной итерации: SYMBOL_BID - 57.14 ns, GetBid() - 157.85 ns, sum1 = 124053724.3725583, sum2 = 44907061.11418578
2020.10.26 22:16:21.553 FxSaberBidSpeed (EURUSD,M1)     EURUSD: SYMBOL_BID быстрее GetBid() в 3.15 раза. Среднее время одной итерации: SYMBOL_BID - 52.80 ns, GetBid() - 166.11 ns, sum1 = 78375839.87008552, sum2 = 24913626.42960918
2020.10.26 22:16:24.865 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.77 раза. Среднее время одной итерации: SYMBOL_BID - 56.94 ns, GetBid() - 157.50 ns, sum1 = 127392085.5933389, sum2 = 46051851.71182434
2020.10.26 22:16:27.678 FxSaberBidSpeed (USDCAD,M1)     USDCAD: SYMBOL_BID быстрее GetBid() в 2.77 раза. Среднее время одной итерации: SYMBOL_BID - 57.13 ns, GetBid() - 158.30 ns, sum1 = 129851046.9417646, sum2 = 46862113.16739535

Therefore, I think fxsaber's version of the test is far from objective.

I did not load CPU with agents, but with this script. It was more efficient.

Files:
LSD.mq5  6 kb
 

after a slight modification of the fxsaber test to clearly demonstrate what percentage of iterations are accounted for in the calculations:

2020.10.26 22:45:03.679 FxSaberBidSpeed (USDCAD,M1)     Alert: , TimeBid1-TimeBid2 = 2142416 mcs., TimeBid1 = 2858669, TimeBid2 = 716253,  Всего итераций - 31456223, из них принято во внимание, NBid1 = 3015, NBid2 = 1714
2020.10.26 22:45:05.739 FxSaberBidSpeed (BTCUSD,M1)     Alert: , TimeBid1-TimeBid2 = 1521696 mcs., TimeBid1 = 2282285, TimeBid2 = 760589,  Всего итераций - 31417549, из них принято во внимание, NBid1 = 1794, NBid2 = 1418
2020.10.26 22:45:06.006 FxSaberBidSpeed (USDJPY,M1)     Alert: , TimeBid1-TimeBid2 = 2241890 mcs., TimeBid1 = 3204507, TimeBid2 = 962617,  Всего итераций - 54138004, из них принято во внимание, NBid1 = 4401, NBid2 = 2083
2020.10.26 22:45:09.099 FxSaberBidSpeed (EURUSD,M1)     Alert: , TimeBid1-TimeBid2 = 1000828 mcs., TimeBid1 = 1496646, TimeBid2 = 495818,  Всего итераций - 10037824, из них принято во внимание, NBid1 = 2429, NBid2 = 1711
2020.10.26 22:45:14.803 FxSaberBidSpeed (USDCAD,M1)     Alert: , TimeBid1-TimeBid2 = 2676273 mcs., TimeBid1 = 3916168, TimeBid2 = 1239895, Всего итераций - 41606744, из них принято во внимание, NBid1 = 4935, NBid2 = 3790
2020.10.26 22:45:15.745 FxSaberBidSpeed (BTCUSD,M1)     Alert: , TimeBid1-TimeBid2 = 1521696 mcs., TimeBid1 = 2282285, TimeBid2 = 760589,  Всего итераций - 31417549, из них принято во внимание, NBid1 = 1794, NBid2 = 1418
2020.10.26 22:45:16.115 FxSaberBidSpeed (USDJPY,M1)     Alert: , TimeBid1-TimeBid2 = 2653810 mcs., TimeBid1 = 4195095, TimeBid2 = 1541285, Всего итераций - 64310228, из них принято во внимание, NBid1 = 6486, NBid2 = 3879
2020.10.26 22:45:19.834 FxSaberBidSpeed (EURUSD,M1)     Alert: , TimeBid1-TimeBid2 = 1949809 mcs., TimeBid1 = 3091755, TimeBid2 = 1141946, Всего итераций - 19435170, из них принято во внимание, NBid1 = 4724, NBid2 = 3547

i.e. approximately 0.01%.

You bet.
If the average execution time of SymbolInfoDouble(_Symbol, SYMBOL_BID) is about 50 nanoseconds, only those with execution time over 100 000 nanoseconds are taken into account.

Files:
 
Nikolai Semko:

after a slight modification of the fxsaber test to clearly demonstrate what percentage of iterations are accounted for in the calculations:

i.e. approximately 0.01%.

You bet.
If the average execution time of SymbolInfoDouble(_Symbol, SYMBOL_BID) is about 50 nanoseconds, only those iterations greater than 100 000 nanoseconds are counted.

We could have simply made the condition not more than 100 µs, but more than 3 µs. The result was apparently the same. The thought was that a segmental study and in different execution conditions there may be a difference in different segments and in different sections. Execution priorities are often made depending on anything. At a light load some priorities, at high load others, at critical ones, those that do not let the computer hang and crash, and performance goes into the background.

Generally, trading at a load of more than 70% of the hardware is not right. It's almost critical performance. The iron load on combat EAs should not be more than 60%.

 
I won't be at my computer for a while, so I'll keep it short.

In algotrading, no one cares about the average hospital temperature when there are regular slowdowns. Getting prices in milliseconds is a regular occurrence. And that's in a combat environment.

If it is possible to obtain prices without lag spikes at important moments of trading, then I will fight for this very opportunity.

I have proved by code that such a crutch exists. If you want to avoid lags, use the crutch.

No one here has ever looked at the code comparing received prices when working with a tumbler as well. And there, to put it mildly, are serious questions.

The fact is, the regular function lags catastrophically more often than the crutch. And I don't care that the average time is close to zero. It's the lags that cause problems during trading

Want HFT - forget even the slow millisecond level for now.
 
do you already have HFT brokers?)
 
secret:
and do you already have HFT brokers?)
Yes.
 
Igor Makanu:

try to test SymbolInfoTick when there is only one symbol in the market overview and when there are dozens of symbols, but ask for one tool - like in your example

there is a high probability that the server is sending compressed traffic and that SymbolInfoTick is experiencing this intermittent slowdown when decompressing the data

i.e., when there are a lot of symbols, there will be even more frequent or deeper dips in test time

In recent builds, receiving tick stream has no effect even theoretically. Practically, SymbolInfoTick already works with cache, but some citizens keep looking for a black cat.

I don't see the point in testing on 80% loaded processor.

It's not even 80% in the test. There are 6 agents running on 4 cores, i.e. 100% guaranteed.

The only question is how his system's task scheduler is handling the situation. At the same time, the authors make claims that it is the implementation of the terminal that is to blame.

That is, a situation is artificially created when a computer is overloaded, when literally everything on it slows down, and then some claims are made in the form of "Oh, look, why is the terminal lags sometimes".

Let's close our eyes to the fact that even in such conditions it is "about 0.01%" - to hell with the details! Suffice it to say that "no one cares about the average hospital temperature", "lags cause problems when trading" and "we want HFT".

Moreover, of course we want HFT in 20 experts on an old office desktop or a dead virtual machine.

PS PositionSelectByTicket() in its implementation certainly has access to a shared resource with access synchronisation. And if you don't select the position on every call, you're reading the old price. It was easier to "snapshot" via SymbolInfoDouble.

Ордерa, позиции и сделки в MetaTrader 5
Ордерa, позиции и сделки в MetaTrader 5
  • www.mql5.com
Конечной целью трейдера является извлечение прибыли посредством торговых операций на финансовых рынках. В этой статье дается описание терминов и процессов торговой платформы MetaTarder 5, знание которых необходимо для правильного понимания работы торговых функций языка MQL5. Ордера — это принятые торговым сервером запросы на совершение торговых...
 
can the realtime kernel help in any way?