MT5 und Geschwindigkeit in Aktion - Seite 50

 

Forum zum Thema Handel, automatisierte Handelssysteme und Testen von Handelsstrategien

MT5 und Geschwindigkeit in Aktion

fxsaber, 2020.10.07 11:13

#include <fxsaber\Benchmark\Benchmark.mqh> // https://www.mql5.com/ru/code/31279

void OnTick()
{
  _BV(Print(""), 1);
}

Kann nicht überprüfen, wie es auf langsamen VPS sein wird.

Wenn Sie nach OrderSend etwas ausdrucken (z.B. das Ergebnis des Bestellungsversands), ist es besser, sie in einer String-Variablen zu sammeln und sie beim Verlassen der On-Funktion zum Drucken zu senden.

Andernfalls können Sie viel Geld verlieren, wenn Sie eine Verbindung zu einem Print-Snapshot herstellen. Wie viel - kann man beantworten, wenn jemand den obigen Berater auf seinem VPS betreibt.


ZZZ Die einfachste Umsetzung.

#include <fxsaber\Benchmark\Benchmark.mqh> // https://www.mql5.com/ru/code/31279

class PRINT
{
private:
  string Str;
  
public:
  PRINT() : Str(NULL) { ::StringSetLength(this.Str, 5000); }
  ~PRINT() { if (this.Str != NULL) ::Print(this.Str); }
  
  template <typename T>
  void Add( const T PrintStr ) { this.Str += ((this.Str == NULL) ? NULL : "\n") + (string)PrintStr; }
};

#define Print PrintObj.Add // Закомментируйте, чтобы посмотреть скорость обычного Print.

void OnTick()
{  
  PRINT PrintObj; // Накопитель Print-ов.
  
  for (int i = 0; i < 5; i++)
  {
    _BV(Print(i), 1)
    
    Sleep(100); // Эмуляция OrderSend
  }
}

Auf einem schnellen Rechner ist diese Lösung viel schneller als der übliche Ansatz. Wie auf VPS - ich weiß es nicht.

 
fxsaber:

Wenn Sie nach OrderSend etwas ausdrucken (z.B. das Ergebnis des Bestellungsversands), ist es besser, diese in einer String-Variablen zu sammeln und sie beim Verlassen der On-Funktion an den Drucker zu senden.

Andernfalls können Sie viel Geld verlieren, wenn Sie eine Verbindung zu einem Print-Snapshot herstellen. Wie viel - kann man beantworten, wenn jemand den obigen Berater auf seinem VPS betreibt.

Auf meinem $3 VPS

2020.10.08 09:50:59.631 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 3121 mсs.
2020.10.08 09:50:59.724 Test Print (EURUSD,H1)  
2020.10.08 09:50:59.724 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 78 mсs.
2020.10.08 09:50:59.837 Test Print (EURUSD,H1)  
2020.10.08 09:50:59.837 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 86 mсs.
2020.10.08 09:50:59.930 Test Print (EURUSD,H1)  
2020.10.08 09:50:59.931 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 159 mсs.
2020.10.08 09:51:00.036 Test Print (EURUSD,H1)  
2020.10.08 09:51:00.036 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 84 mсs.
2020.10.08 09:51:00.138 Test Print (EURUSD,H1)  
2020.10.08 09:51:00.138 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 94 mсs.
2020.10.08 09:51:00.243 Test Print (EURUSD,H1)  
2020.10.08 09:51:00.243 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 86 mсs.
2020.10.08 09:51:00.380 Test Print (EURUSD,H1)  
2020.10.08 09:51:00.380 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 54 mсs.
2020.10.08 09:51:00.973 Test Print (EURUSD,H1)  
2020.10.08 09:51:00.973 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 79 mсs.
2020.10.08 09:51:01.129 Test Print (EURUSD,H1)  
2020.10.08 09:51:01.129 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 91 mсs.
2020.10.08 09:51:01.186 Test Print (EURUSD,H1)  
2020.10.08 09:51:01.186 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 60 mсs.
2020.10.08 09:51:01.320 Test Print (EURUSD,H1)  
2020.10.08 09:51:01.321 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 75 mсs.
2020.10.08 09:51:01.402 Test Print (EURUSD,H1)  
2020.10.08 09:51:01.402 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 86 mсs.
2020.10.08 09:51:01.546 Test Print (EURUSD,H1)  
2020.10.08 09:51:01.555 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 72 mсs.
2020.10.08 09:51:02.158 Test Print (EURUSD,H1)  
2020.10.08 09:51:02.158 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 67 mсs.
2020.10.08 09:51:04.651 Test Print (EURUSD,H1)  
2020.10.08 09:51:04.651 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 74 mсs.
2020.10.08 09:51:04.929 Test Print (EURUSD,H1)  
2020.10.08 09:51:04.930 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 200 mсs.
2020.10.08 09:51:07.200 Test Print (EURUSD,H1)  
2020.10.08 09:51:07.200 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 58 mсs.
2020.10.08 09:51:07.330 Test Print (EURUSD,H1)  
2020.10.08 09:51:07.330 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 68 mсs.
2020.10.08 09:51:07.452 Test Print (EURUSD,H1)  
2020.10.08 09:51:07.460 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 77 mсs.
2020.10.08 09:51:07.728 Test Print (EURUSD,H1)  
2020.10.08 09:51:07.728 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 64 mсs.
2020.10.08 09:51:07.870 Test Print (EURUSD,H1)  
2020.10.08 09:51:07.870 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 72 mсs.
2020.10.08 09:51:07.967 Test Print (EURUSD,H1)  
2020.10.08 09:51:07.967 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 58 mсs.
2020.10.08 09:51:08.130 Test Print (EURUSD,H1)  
2020.10.08 09:51:08.130 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 56 mсs.
2020.10.08 09:51:11.274 Test Print (EURUSD,H1)  
2020.10.08 09:51:11.275 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 63 mсs.
2020.10.08 09:51:11.409 Test Print (EURUSD,H1)  
2020.10.08 09:51:11.409 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 73 mсs.
2020.10.08 09:51:11.903 Test Print (EURUSD,H1)  
2020.10.08 09:51:11.903 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 86 mсs.
2020.10.08 09:51:12.022 Test Print (EURUSD,H1)  
2020.10.08 09:51:12.022 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 79 mсs.
2020.10.08 09:51:12.699 Test Print (EURUSD,H1)  
2020.10.08 09:51:12.700 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 69 mсs.
2020.10.08 09:51:12.977 Test Print (EURUSD,H1)  
2020.10.08 09:51:12.977 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 67 mсs.
2020.10.08 09:51:13.226 Test Print (EURUSD,H1)  
2020.10.08 09:51:13.226 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 98 mсs.
2020.10.08 09:51:13.412 Test Print (EURUSD,H1)  
2020.10.08 09:51:13.412 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 93 mсs.
2020.10.08 09:51:13.854 Test Print (EURUSD,H1)  
2020.10.08 09:51:13.854 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 59 mсs.
2020.10.08 09:51:14.000 Test Print (EURUSD,H1)  
2020.10.08 09:51:14.000 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 62 mсs.
2020.10.08 09:51:18.343 Test Print (EURUSD,H1)  
2020.10.08 09:51:18.343 Test Print (EURUSD,H1)  Alert: Time[Test Print.mq5 5: Print()] = 86 mсs.
 
Edgar Akhmadeev:

Auf meinem $3 VPS.

Ich danke Ihnen. Das ist auf jeden Fall eine bessere Lösung.

 
fxsaber:


#include <fxsaber\Benchmark\Benchmark.mqh> // https://www.mql5.com/ru/code/31279

long GetAnotherChart()
{
  long Chart = ::ChartFirst();
  
  while (Chart == ChartID())
    Chart = ChartNext(Chart);
 
  return(Chart);     
}


void OnTick()
{  
  const long Chart = GetAnotherChart();
  
  if (Chart)
    _B(EventChartCustom(Chart, 123, 0, 0, NULL), 1);
  
  _B(EventChartCustom(0, 123, 0, 0, NULL), 1);
}

Es ist teurer, in die Kartei eines anderen Unternehmens zu senden als in die eigene.

Versuchen Sie es auf diese Weise:

_B(EventChartCustom(-1, 123, 0, 0, NULL), 1);
 
Anton:

Versuchen Sie es auf diese Weise:

// https://www.mql5.com/ru/forum/342090/page50#comment_18647171
class PRINT
{
private:
  string Str;
public:
  PRINT() : Str(NULL) { ::StringSetLength(this.Str, 5000); }
  ~PRINT() { if (this.Str != NULL) ::Print(this.Str); }
  
  template <typename T>
  void Add( const T PrintStr ) { this.Str += ((this.Str == NULL) ? NULL : "\n") + (string)PrintStr; }
};

#define Alert PrintObj.Add

PRINT PrintObj;

//#define BENCHMARK_OFF // Выключение замеров.
#include <fxsaber\Benchmark\Benchmark.mqh> // https://www.mql5.com/ru/code/31279

void OnTick()
{  
  _B(EventChartCustom(-1, 123, GetMicrosecondCount(), 0, NULL), 1);
}

void OnChartEvent(const int id, const long& lparam,const double& dparam,const string& sparam)
{
  if (id == 1123)
    Print("Time[from OnTick To OnChartEvent] = " + (string)(GetMicrosecondCount() - lparam) + " mcs.");
}


Ergebnis.

2020.10.08 11:35:52.050 Benchmark.mqh: TimeAvg[GetMicrosecondsCount()] = 0 mcs.
2020.10.08 11:35:52.050 Benchmark.mqh is On.
2020.10.08 11:35:55.617 Time[from OnTick To OnChartEvent] = 14 mcs.
2020.10.08 11:35:55.821 Time[from OnTick To OnChartEvent] = 3 mcs.
2020.10.08 11:35:56.729 Time[from OnTick To OnChartEvent] = 4 mcs.
2020.10.08 11:35:56.932 Time[from OnTick To OnChartEvent] = 9 mcs.
2020.10.08 11:35:57.841 Time[from OnTick To OnChartEvent] = 9 mcs.
2020.10.08 11:35:58.177 Bench_Stack = 0, 1 <= Time[Test9.mq5 23 in OnTick: EventChartCustom(-1,123,GetMicrosecondCount(),0,NULL)] = 2 mcs.
2020.10.08 11:35:58.177 Bench_Stack = 0, 1 <= Time[Test9.mq5 23 in OnTick: EventChartCustom(-1,123,GetMicrosecondCount(),0,NULL)] = 2 mcs.
2020.10.08 11:35:58.177 Bench_Stack = 0, 1 <= Time[Test9.mq5 23 in OnTick: EventChartCustom(-1,123,GetMicrosecondCount(),0,NULL)] = 2 mcs.


Wenn die Belichtungsmessung ausgeschaltet ist.

2020.10.08 11:15:19.084 Benchmark.mqh: TimeAvg[GetMicrosecondsCount()] = 0 mcs.
2020.10.08 11:15:19.084 Benchmark.mqh is Off.
2020.10.08 11:15:24.171 Time[from OnTick To OnChartEvent] = 4 mcs.
2020.10.08 11:15:24.376 Time[from OnTick To OnChartEvent] = 3 mcs.
2020.10.08 11:15:27.010 Time[from OnTick To OnChartEvent] = 3 mcs.
2020.10.08 11:15:31.859 Time[from OnTick To OnChartEvent] = 5 mcs.
2020.10.08 11:15:32.266 Time[from OnTick To OnChartEvent] = 4 mcs.
2020.10.08 11:15:32.470 Time[from OnTick To OnChartEvent] = 3 mcs.
2020.10.08 11:15:32.670 Time[from OnTick To OnChartEvent] = 6 mcs.


D.h. es dauert weniger als 10µs, um auf "OnEmpty" umzuschalten.

Warum nicht das Gleiche für Null tun?

 
fxsaber:

Das heißt, es dauert weniger als 10µs, um auf "OnEmpty" umzuschalten.

Warum nicht das Gleiche für Null?

Unterschiedliche Bedeutung und unterschiedlicher Ausführungsmechanismus. 0 - Ereignis zur "eigenen" Karte. -1 - Ereignis in der eigenen Chart-Warteschlange.

 

Forum zum Thema Handel, automatisierte Handelssysteme und Testen von Handelsstrategien

MT5 und Geschwindigkeit in Aktion

fxsaber, 2020.10.07 12:41

Ich habe nie versucht, TimeCurrentMsc in MQL5 zu verwenden, trotz meiner wiederholten Anfragen.

Wird es das sein?

 
Anton:

Unterschiedliche Bedeutung und unterschiedlicher Ausführungsmechanismus. 0 ist ein Ereignis in der Warteschlange der "eigenen" Karte. -1 - Ereignis in eigener Warteschlange.

Es stellt sich heraus, dass durch -1 Asynchronität derselbe Alert nicht implementiert werden kann.

 
fxsaber:

Das bedeutet, dass es weniger als 10 Mikrosekunden dauert, um auf OnEmpty umzuschalten.

Wie Sie sehen können, wurde mit Ihrer Hilfe alles schneller gelöst als die optimistischsten Vorhersagen, es stellte sich heraus, dass es eine versteckte Hintertür gibt

 
fxsaber:

Wird es sie geben?

Nicht ganz dasselbe, aber ein Zähler nach mcs-Intervall.
Ja,TimeCurrentMcs wärebesser, ich schließe mich dem Wunsch an.

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
   ulong mcs = 0;
   
   while(!_StopFlag)
   {
      mcs = GetMicrosecondCount();
     
      switch(GetInterval(mcs, 5000000)) //5 секунд
      { 
         case 1: 
            Print((string) mcs); 
            break;
         case 0:       
            break;             
      }    
   }
}

//--------------------------------------------------------------------
//Получить интервал 
ulong prevCount = 0;
int GetInterval(ulong currCount, ulong mcsIntrval)
{ 
   int res = 0;   
   switch((currCount - prevCount) > mcsIntrval) 
   { 
      case 1: 
         prevCount = currCount;
         res = 1; 
         break; 
      default:
         break;   
   } 
   
   return(res);
}
2020.10.09 00:15:45.712 TestScript (MNQZ20,M1)  5000001
2020.10.09 00:15:50.712 TestScript (MNQZ20,M1)  10000002
2020.10.09 00:15:55.712 TestScript (MNQZ20,M1)  15000003
2020.10.09 00:16:00.712 TestScript (MNQZ20,M1)  20000004
2020.10.09 00:16:05.712 TestScript (MNQZ20,M1)  25000006
2020.10.09 00:16:10.712 TestScript (MNQZ20,M1)  30000007
2020.10.09 00:16:15.712 TestScript (MNQZ20,M1)  35000008
2020.10.09 00:16:20.712 TestScript (MNQZ20,M1)  40000009
2020.10.09 00:16:25.713 TestScript (MNQZ20,M1)  45000581
2020.10.09 00:16:30.713 TestScript (MNQZ20,M1)  50000582
Grund der Beschwerde: