Testare 'CopyTicks'. - pagina 22

 
fxsaber:
No, purtroppo. Renat ha sostenuto che il vetro è permanentemente in streaming per tutto il marketwatch. Ma questa non è una soluzione opportuna (dispendiosa) per la maggior parte delle situazioni.

È l'unica opzione possibile. Le puntate in streaming sono un flusso nativo e inseparabile di zecche.

Tutto nella piattaforma è interconnesso e richiede una sincronizzazione globale dei dati. E il flusso di zecche gioca un ruolo cruciale in questo.

 
Renat Fatkhullin:

Questa è l'unica opzione possibile. I tassi di flusso sono un flusso nativo e inseparabile di zecche.

Tutto nella piattaforma è interconnesso e richiede una sincronizzazione globale dei dati. E il flusso di zecche gioca un ruolo fondamentale in questo.

E se nessun EA è iscritto a BookEvent?

Consigliate di tagliare MarketWatch per migliorare le prestazioni?

 
Renat Fatkhullin:

Ma soprattutto, i calcoli della frequenza di campionamento di cui sopra sono irrilevanti. Sono fatti così maldestramente (misurando tutto tranne il tempo di CopyTicks), che è persino sorprendente.

Non ho guardato i calcoli della velocità, mi misurerò con il metodo che hai descritto sopra.
 
fxsaber:

E se nessun EA è iscritto a BookEvent?

Consigliate di tagliare Marketwatch per migliorare le prestazioni?

Taglialo se vuoi.

 
Renat Fatkhullin:

È così che si testa CopyTicks:

MqlTick ExtArr[2048];
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   ulong from   =(TimeTradeServer()-1200)*1000;
   ulong ticks  =GetMicrosecondCount();
   int   records=CopyTicks(_Symbol,ExtArr,COPY_TICKS_INFO,from,2048);

   ticks=GetMicrosecondCount()-ticks;
   Print("Time: ",ticks," msc for ",records," records");
  }

Ecco l'output in microsecondi: 95 microsecondi per campione di 2048 tick INFO per gli ultimi 20 minuti

2016.10.18 14:15:38.673 TEST (USDCHF,M1)        Time: 95 msc for 1206 records
Questo è radicalmente diverso dalle decine di millisecondi che hai affermato. Questo perché non hai misurato i CopyTicks.

Mi sono già mangiato l'occhio del gatto su questo. Ho fatto molti test con CopyTicks. Questa volta ho deciso che è sufficiente eseguire l'indicatore.

La tua variante.

Network 'xxx': authorized on MetaQuotes-Demo through Access Point EU Amsterdam (ping: 54.84 ms)

2016.10.18 14:29:11.966 Test14 (GBPUSD,M1)      Time: 20263 msc for 2048 records
2016.10.18 14:29:10.841 Test14 (GBPUSD,M1)      Time: 13190 msc for 2048 records
2016.10.18 14:29:07.788 Test14 (GBPUSD,M1)      Time: 13344 msc for 2048 records
2016.10.18 14:29:07.738 Test14 (GBPUSD,M1)      Time: 12751 msc for 2048 records
 

Si tratta di entrare in una cache stretta per le ultime 4096 citazioni.

Qualunque cosa ci entri impiega microsecondi, e qualunque cosa più lunga richiede l'accesso alla storia (incluso il disco).

Pertanto, il mio esempio di recupero di tick per 20 min. su USDCHF, che è raramente aggiornato, era nella cache, ma su GBPUSD, ha già superato gli ultimi 4096 tick e doveva andare al lontano database.

Se imposto ulong da =(TimeTradeServer()-600)*1000, allora si adatta anche a GBPUSD.

 
Renat Fatkhullin:

Si tratta di entrare in una cache stretta per le ultime 4096 citazioni.

Qualsiasi cosa ci entri impiega microsecondi, e qualsiasi cosa di più richiede l'accesso alla storia (incluso il disco).

Sul tuo demo questo è effettivamente il caso. Su BCS non lo fa.

Network 'xxx': authorized on BCS-MetaTrader5 through Access Server #2 (ping: 46.66 ms)


2016.10.18 15:12:32.949 Test14 (Si-12.16,M1)    Time: 29089 msc for 1503 records
2016.10.18 15:12:32.822 Test14 (Si-12.16,M1)    Time: 33207 msc for 1501 records
2016.10.18 15:12:32.639 Test14 (Si-12.16,M1)    Time: 21389 msc for 1500 records
2016.10.18 15:12:31.959 Test14 (Si-12.16,M1)    Time: 21926 msc for 1500 records

E su Alpari non è affatto buono.

Network 'xxx': authorized on Alpari-MT5 through mt5.nl.3 (ping: 61.87 ms)

2016.10.18 15:14:47.159 Test14 (GBPUSD,M1)      Time: 31086 msc for 1836 records
2016.10.18 15:14:46.999 Test14 (GBPUSD,M1)      Time: 30698 msc for 1836 records
2016.10.18 15:14:46.779 Test14 (GBPUSD,M1)      Time: 46306 msc for 1836 records
2016.10.18 15:14:46.612 Test14 (GBPUSD,M1)      Time: 30440 msc for 1836 records
2016.10.18 15:14:46.532 Test14 (GBPUSD,M1)      Time: 36227 msc for 1836 records

Pertanto, il mio esempio di recupero dei tick per 20 minuti su USDCHF aggiornato raramente si adatta alla cache, ma per GBPUSD ha già superato gli ultimi 4096 tick e mi costringe ad andare in un database lontano.

Commentato sopra sull'inconveniente di copytix. L'indicatore presentato sta rallentando perché è costretto a chiamare più volte copyix. E tutti i ritardi sono dovuti a questo. Ecco il motivo

Forum sul trading, sistemi di trading automatico e test di strategie di trading

Testare 'CopyTicks'.

fxsaber, 2016.10.11 19:23

Qual è l'algoritmo ottimale (più veloce) per ottenere i tick da_time a_time?

È stata proposta una soluzione

Forum sul trading, sistemi di trading automatico e test di strategie di trading

Testare 'CopyTicks'.

fxsaber, 2016.10.12 08:44

Quando non è zero Da dentro CopyTicks sta cercando (probabilmente una ricerca binaria) un posto da cui partire - un indice nella base interna.

Si prega di aggiungere una funzione che restituisca l'indice nel database in base al tempo. Allora questo compito potrà essere risolto in modo ottimale

Ora, per scaricare i tick tra le date, dobbiamo fare delle query per QUALSIASI numero di tick, a partire dalla data di inizio. E poi controllare ogni volta se ha raggiunto la data finale. E tenendo conto del fatto, che ogni richiesta copytix è molto costosa, e si ottiene tali freni.

 
fxsaber:

E su Alpari non è affatto buono

Alpari è stato sistemato, sembra. La BCS non l'ha fatto.

Sarebbe bene avere una cache dei dati copiati richiesti in precedenza. Bene e se la copia è fatta in diversi passi (da[i] a da[i+ 1]), sarebbe logico fare molta cache dopo la prima richiesta.

Tutto sommato, non è chiaro come la funzione sia organizzata internamente. Ma è difficile lavorarci - al 100%.

 
Consulente
long LastTime = 0; // time_msc-время последнего тика (самого свежего), полученного из истории
int Count = 0;     // Количество тиков в последенем запросе, у которых time_msc == LastTime

// Возвращает свежие тики, пришедшие после предыдущего вызова
int GetFreshTicks( MqlTick &Ticks[], const uint flags = COPY_TICKS_INFO, const uint count = 2000 )
{
  int Res = 0;

  MqlTick NewTicks[];
  const int NewAmount = CopyTicks(Symbol(), NewTicks, flags, LastTime, count);

  if ((NewAmount > 0) && (Count < NewAmount))
  {
    Res = ArrayCopy(Ticks, NewTicks, 0, Count);

    // Взяли крайнее время из текущей истории
    LastTime = NewTicks[NewAmount - 1].time_msc;
    Count = 1;

    // Находим (Count) в текущей истории количество тиков со временем LastTime
    for (int i = NewAmount - 2; i >= 0; i--)
    {
      if (NewTicks[i].time_msc < LastTime)
        break;

      Count++;
    }
  }

  return(Res);
}

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

void OnTick( void )
{
  // возьмем тики с начала утренней сессии
  LastTime = (TimeCurrent() - (TimeCurrent() % (24 * 3600))) * 1000;
  
  MqlTick Ticks[];

  int i = 0;
  int Sum = 0;

  const ulong StartTime  =GetMicrosecondCount();
  
  // Взяли свеженькие тики
  int Amount = GetFreshTicks(Ticks);
    
  while (Amount > 0)
  {
    Sum += Amount;
    i++;
    
    Print(TOSTRING(i) + TOSTRING(Amount) + TOSTRING(Sum) + TOSTRING(GetMicrosecondCount() - StartTime));
    
    // Взяли свеженькие тики  
    Amount = GetFreshTicks(Ticks);    
  }  
}
Risultato su Metaquotes-demo
2016.10.18 16:06:18.744 Test15 (GBPUSD,M1)       i = 40 Amount = 1453 Sum = 79414 GetMicrosecondCount()-StartTime = 584393
2016.10.18 16:06:18.744 Test15 (GBPUSD,M1)       i = 39 Amount = 1999 Sum = 77961 GetMicrosecondCount()-StartTime = 584314
2016.10.18 16:06:18.729 Test15 (GBPUSD,M1)       i = 38 Amount = 1999 Sum = 75962 GetMicrosecondCount()-StartTime = 568509
2016.10.18 16:06:18.714 Test15 (GBPUSD,M1)       i = 37 Amount = 1999 Sum = 73963 GetMicrosecondCount()-StartTime = 552582
2016.10.18 16:06:18.696 Test15 (GBPUSD,M1)       i = 36 Amount = 1999 Sum = 71964 GetMicrosecondCount()-StartTime = 536790
2016.10.18 16:06:18.681 Test15 (GBPUSD,M1)       i = 35 Amount = 1999 Sum = 69965 GetMicrosecondCount()-StartTime = 520432
2016.10.18 16:06:18.666 Test15 (GBPUSD,M1)       i = 34 Amount = 1999 Sum = 67966 GetMicrosecondCount()-StartTime = 504725
2016.10.18 16:06:18.649 Test15 (GBPUSD,M1)       i = 33 Amount = 1999 Sum = 65967 GetMicrosecondCount()-StartTime = 488911
2016.10.18 16:06:18.634 Test15 (GBPUSD,M1)       i = 32 Amount = 1999 Sum = 63968 GetMicrosecondCount()-StartTime = 473372
2016.10.18 16:06:18.619 Test15 (GBPUSD,M1)       i = 31 Amount = 1999 Sum = 61969 GetMicrosecondCount()-StartTime = 458022
2016.10.18 16:06:18.604 Test15 (GBPUSD,M1)       i = 30 Amount = 1999 Sum = 59970 GetMicrosecondCount()-StartTime = 442557
2016.10.18 16:06:18.589 Test15 (GBPUSD,M1)       i = 29 Amount = 1999 Sum = 57971 GetMicrosecondCount()-StartTime = 427044
2016.10.18 16:06:18.571 Test15 (GBPUSD,M1)       i = 28 Amount = 1999 Sum = 55972 GetMicrosecondCount()-StartTime = 411524
2016.10.18 16:06:18.556 Test15 (GBPUSD,M1)       i = 27 Amount = 1999 Sum = 53973 GetMicrosecondCount()-StartTime = 396539
2016.10.18 16:06:18.541 Test15 (GBPUSD,M1)       i = 26 Amount = 1999 Sum = 51974 GetMicrosecondCount()-StartTime = 381185
2016.10.18 16:06:18.526 Test15 (GBPUSD,M1)       i = 25 Amount = 1999 Sum = 49975 GetMicrosecondCount()-StartTime = 366146
2016.10.18 16:06:18.511 Test15 (GBPUSD,M1)       i = 24 Amount = 1999 Sum = 47976 GetMicrosecondCount()-StartTime = 351066
2016.10.18 16:06:18.496 Test15 (GBPUSD,M1)       i = 23 Amount = 1999 Sum = 45977 GetMicrosecondCount()-StartTime = 336183
2016.10.18 16:06:18.481 Test15 (GBPUSD,M1)       i = 22 Amount = 1999 Sum = 43978 GetMicrosecondCount()-StartTime = 321109
2016.10.18 16:06:18.466 Test15 (GBPUSD,M1)       i = 21 Amount = 1999 Sum = 41979 GetMicrosecondCount()-StartTime = 306119
2016.10.18 16:06:18.449 Test15 (GBPUSD,M1)       i = 20 Amount = 1999 Sum = 39980 GetMicrosecondCount()-StartTime = 288558
2016.10.18 16:06:18.434 Test15 (GBPUSD,M1)       i = 19 Amount = 1999 Sum = 37981 GetMicrosecondCount()-StartTime = 273758
2016.10.18 16:06:18.419 Test15 (GBPUSD,M1)       i = 18 Amount = 1999 Sum = 35982 GetMicrosecondCount()-StartTime = 259255
2016.10.18 16:06:18.406 Test15 (GBPUSD,M1)       i = 17 Amount = 1999 Sum = 33983 GetMicrosecondCount()-StartTime = 244750
2016.10.18 16:06:18.391 Test15 (GBPUSD,M1)       i = 16 Amount = 1999 Sum = 31984 GetMicrosecondCount()-StartTime = 230100
2016.10.18 16:06:18.371 Test15 (GBPUSD,M1)       i = 15 Amount = 1999 Sum = 29985 GetMicrosecondCount()-StartTime = 216143
2016.10.18 16:06:18.361 Test15 (GBPUSD,M1)       i = 14 Amount = 1999 Sum = 27986 GetMicrosecondCount()-StartTime = 201830
2016.10.18 16:06:18.346 Test15 (GBPUSD,M1)       i = 13 Amount = 1999 Sum = 25987 GetMicrosecondCount()-StartTime = 186887
2016.10.18 16:06:18.331 Test15 (GBPUSD,M1)       i = 12 Amount = 1999 Sum = 23988 GetMicrosecondCount()-StartTime = 172667
2016.10.18 16:06:18.311 Test15 (GBPUSD,M1)       i = 11 Amount = 1999 Sum = 21989 GetMicrosecondCount()-StartTime = 158356
2016.10.18 16:06:18.299 Test15 (GBPUSD,M1)       i = 10 Amount = 1999 Sum = 19990 GetMicrosecondCount()-StartTime = 143450
2016.10.18 16:06:18.289 Test15 (GBPUSD,M1)       i = 9 Amount = 1999 Sum = 17991 GetMicrosecondCount()-StartTime = 128520
2016.10.18 16:06:18.269 Test15 (GBPUSD,M1)       i = 8 Amount = 1999 Sum = 15992 GetMicrosecondCount()-StartTime = 114209
2016.10.18 16:06:18.256 Test15 (GBPUSD,M1)       i = 7 Amount = 1999 Sum = 13993 GetMicrosecondCount()-StartTime = 100016
2016.10.18 16:06:18.246 Test15 (GBPUSD,M1)       i = 6 Amount = 1999 Sum = 11994 GetMicrosecondCount()-StartTime = 85745
2016.10.18 16:06:18.231 Test15 (GBPUSD,M1)       i = 5 Amount = 1999 Sum = 9995 GetMicrosecondCount()-StartTime = 71438
2016.10.18 16:06:18.219 Test15 (GBPUSD,M1)       i = 4 Amount = 1999 Sum = 7996 GetMicrosecondCount()-StartTime = 57293
2016.10.18 16:06:18.204 Test15 (GBPUSD,M1)       i = 3 Amount = 1999 Sum = 5997 GetMicrosecondCount()-StartTime = 43192
2016.10.18 16:06:18.181 Test15 (GBPUSD,M1)       i = 2 Amount = 1999 Sum = 3998 GetMicrosecondCount()-StartTime = 28943
2016.10.18 16:06:18.171 Test15 (GBPUSD,M1)       i = 1 Amount = 1999 Sum = 1999 GetMicrosecondCount()-StartTime = 15160
80K ticks in mezzo secondo - lento! Dire che avremmo dovuto richiedere più zecche invece di 2000 zecche alla volta è ovviamente possibile. Qual è allora il valore di richiesta ottimale?
 
fxsaber:
80K ticks in mezzo secondo è lento! Dicendo che era necessario richiedere non 2000 zecche alla volta, ma di più, ovviamente, è possibile. Quale valore di richiesta è ottimale allora?

È ottimale scaricare quello che ti serve in profondità una volta sola, e poi scaricarne di nuovi dalla cache vicina solo in microsecondi.

Se ogni volta che fai delle interrogazioni profonde con caduta sul disco, allora ovviamente è colpa tua.