Caratteristiche del linguaggio mql5, sottigliezze e tecniche - pagina 104

 
Andrey Khatimlianskii:

Quanti strumenti nella revisione del mercato?

61.

 
fxsaber:

Nella build 1907 i bug sono miracolosamente scomparsi. Non so nemmeno se devo tornare indietro per trovarli, o se qualcosa in questo posto è stato appena aggiustato...

 

Domanda sulla costruzione degli indicatori

#property indicator_chart_window

#property indicator_buffers 12

#property indicator_plots   6

#property indicator_type1   DRAW_COLOR_LINE

#property indicator_type2   DRAW_COLOR_LINE

#property indicator_type3   DRAW_COLOR_LINE

#property indicator_type4   DRAW_COLOR_LINE

#property indicator_type5   DRAW_COLOR_LINE

#property indicator_type6   DRAW_COLOR_LINE 


SetIndexBuffer(0,upper_line,INDICATOR_DATA);

   SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX);


   PlotIndexSetString(0,PLOT_LABEL,"Upper Line");

   PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);

   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);

   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);

   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp);

   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw);

// ==========

   SetIndexBuffer(2,awera_line,INDICATOR_DATA);

   SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX);


   PlotIndexSetString(1,PLOT_LABEL,"Average Line");

   PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle);

   PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth);

   PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2);

   PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp);

   PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw);

// ==========

   SetIndexBuffer(4,lower_line,INDICATOR_DATA);

   SetIndexBuffer(5,lower_line_color,INDICATOR_COLOR_INDEX);


   PlotIndexSetString(2,PLOT_LABEL,"Lower Line");

   PlotIndexSetInteger(2,PLOT_LINE_STYLE,LowerStyle);

   PlotIndexSetInteger(2,PLOT_LINE_WIDTH,LowerWidth);

   PlotIndexSetInteger(2,PLOT_COLOR_INDEXES,2);

   PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,LowerTrendUp);

   PlotIndexSetInteger(2,PLOT_LINE_COLOR,1,LowerTrendDw);

Quanti buffer di colore si possono usare?

Come sono collegati i buffer tra loro?

#property indicator_buffers 12 // Dichiarare un totale di 12 buffer

#property indicator_plots 6 // costruzioni grafiche

Ho capito bene che specificando indicator_type da 1 a 6, l'indicatore capirà che le linee di colore devono essere disegnate per 6 grafici?

#proprietà indicator_type1 DRAW_COLOR_LINE

#proprietà indicator_type2 DRAW_COLOR_LINE

#proprietà indicator_type3 DRAW_COLOR_LINE

#proprietà indicator_type4 DRAW_COLOR_LINE

#proprietà indicator_type5 DRAW_COLOR_LINE

#proprietà indicator_type6 DRAW_COLOR_LINE


// =====

SetIndexBuffer(0,upper_line,INDICATOR_DATA); // Primo buffer per i dati

SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX); // Secondo buffer per i dati di colore


PlotIndexSetString(0,PLOT_LABEL, "Upper Line"); // Cambia le proprietà del primo buffer

PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);// cambia le proprietà del primo buffer

PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);//cambia le proprietà del primo buffer

PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);// cambia le proprietà del primo buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp); // cambia le proprietà del primo buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw); // cambia le proprietà del primo buffer


SetIndexBuffer(2,awera_line,INDICATOR_DATA); // terzo buffer

SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX); // Quarto buffer di colori


PlotIndexSetString(1,PLOT_LABEL, "Average Line"); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

 
Vladimir Pastushak:

Domanda sulla costruzione degli indicatori

#property indicator_chart_window

#property indicator_buffers 12

#property indicator_plots   6

#property indicator_type1   DRAW_COLOR_LINE

#property indicator_type2   DRAW_COLOR_LINE

#property indicator_type3   DRAW_COLOR_LINE

#property indicator_type4   DRAW_COLOR_LINE

#property indicator_type5   DRAW_COLOR_LINE

#property indicator_type6   DRAW_COLOR_LINE 


SetIndexBuffer(0,upper_line,INDICATOR_DATA);

   SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX);


   PlotIndexSetString(0,PLOT_LABEL,"Upper Line");

   PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);

   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);

   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);

   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp);

   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw);

// ==========

   SetIndexBuffer(2,awera_line,INDICATOR_DATA);

   SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX);


   PlotIndexSetString(1,PLOT_LABEL,"Average Line");

   PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle);

   PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth);

   PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2);

   PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp);

   PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw);

// ==========

   SetIndexBuffer(4,lower_line,INDICATOR_DATA);

   SetIndexBuffer(5,lower_line_color,INDICATOR_COLOR_INDEX);


   PlotIndexSetString(2,PLOT_LABEL,"Lower Line");

   PlotIndexSetInteger(2,PLOT_LINE_STYLE,LowerStyle);

   PlotIndexSetInteger(2,PLOT_LINE_WIDTH,LowerWidth);

   PlotIndexSetInteger(2,PLOT_COLOR_INDEXES,2);

   PlotIndexSetInteger(2,PLOT_LINE_COLOR,0,LowerTrendUp);

   PlotIndexSetInteger(2,PLOT_LINE_COLOR,1,LowerTrendDw);

Quanti buffer di colore si possono usare?

Come sono collegati i buffer tra loro?

#property indicator_buffers 12 // Dichiarare un totale di 12 buffer

#property indicator_plots 6 // costruzioni grafiche

Ho capito bene che specificando indicator_type da 1 a 6, l'indicatore capirà che le linee di colore devono essere disegnate per 6 grafici?

#proprietà indicator_type1 DRAW_COLOR_LINE

#proprietà indicator_type2 DRAW_COLOR_LINE

#proprietà indicator_type3 DRAW_COLOR_LINE

#proprietà indicator_type4 DRAW_COLOR_LINE

#proprietà indicator_type5 DRAW_COLOR_LINE

#proprietà indicator_type6 DRAW_COLOR_LINE


// =====

SetIndexBuffer(0,upper_line,INDICATOR_DATA); // Primo buffer per i dati

SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX); // Secondo buffer per i dati di colore


PlotIndexSetString(0,PLOT_LABEL, "Upper Line"); // Cambia le proprietà del primo buffer

PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);// cambia le proprietà del primo buffer

PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);//cambia le proprietà del primo buffer

PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);// cambia le proprietà del primo buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp); // cambia le proprietà del primo buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw); // cambia le proprietà del primo buffer


SetIndexBuffer(2,awera_line,INDICATOR_DATA); // terzo buffer

SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX); // Quarto buffer di colori


PlotIndexSetString(1,PLOT_LABEL, "Average Line"); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw); // Cambia le proprietà del buffer per SetIndexBuffer(2,awera_line,INDICATOR_DATA);

Faresti meglio a creare un ramo separato per la tua domanda. Questo ramo riguarda le caratteristiche, non dovrebbero esserci discussioni qui.

Per capire meglio il principio del disegno, implementate la funzionalità in modo incrementale. Avete costruito una linea - controllate la sua funzionalità, aggiungete la prossima.

Ogni serie grafica (in questo caso una linea di colore) può avere un solo buffer di colore. Ogni buffer può contenere molti colori.

 
Andrey Khatimlianskii:

Nella build 1907, i bug sono miracolosamente scomparsi. Non so nemmeno se devo tornare indietro per trovarli, o se qualcosa in questo posto è stato appena aggiustato...

Gli errori sono scomparsi, ma i problemi con la coda degli eventi no. Dopo alcune ore il terminale inizia a caricare la CPU fino al 95%. E qualcosa mi dice che le zecche sono saltate.

2018.10.11 23:56:54.069 Terminal        MetaTrader 5 x64 build 1907 started (MetaQuotes Software Corp.)
2018.10.11 23:56:54.139 Terminal        Windows 8.1 (build 9600) x64, IE 11, UAC, Intel Core i5-3570  @ 3.40 GHz, Memory: 11580 / 16346 Mb, Disk: 401 / 499 Gb, GMT+2

@Slava, è cambiato qualcosa in ChartEvent nelle build 19xx? Il problema si riproduce nelle vostre build?

 
Andrey Khatimlianskii:

Gli errori sono scomparsi, ma i problemi della coda degli eventi no. Dopo alcune ore di funzionamento, il terminale comincia a caricare la CPU al 95%. E qualcosa mi dice che mancano le zecche.

@Slava, è cambiato qualcosa in ChartEvent nelle build 19xx? Il vostro problema è riprodotto?

Questo è l'aspetto del monitoraggio delle risorse dopo 15 ore di lavoro del terminale (la frequenza minima di invio degli eventi della spia è di 500 ms):

Anche se il carico della CPU è vicino a 0 per diverse ore dopo l'avvio.

 
Andrey Khatimlianskii:

Questo è l'aspetto del monitoraggio delle risorse dopo 15 ore di funzionamento del terminale (la frequenza minima di invio degli eventi spyware è di 500ms):

Anche se il carico della CPU è vicino a 0 per alcune ore dopo l'avvio.

Bild 1908 - nessun cambiamento.

 

La capacità di sostituire gli operatori della struttura del tipo base permette una certa flessibilità in alcune situazioni.

Come esempio, ecco una delle tecniche per l'ordinamento personalizzato di un array di strutture

// Основная структура
struct A
{
  int a;
  int b;
  
  // Правило сортировки
  bool operator > ( const A& Value ) const 
  {
    return(this.a > Value.a);
  }
};

// Вспомогательная структура для изменения правила сортировки
struct B : A
{
  // Перегрузка правила сортировки
  bool operator > ( const A& Value ) const 
  {
    return(this.b > Value.b);
  }
};

// Простая сортировка
template <typename T1, typename T2> // T2 - по какому правилу сортируем
void Sort( T1 &Array[] )
{
  const int Size = ArraySize(Array);
  
  for (int i = 0; i < Size - 1; i++)
  {
    T2 Min = Array[i];
    int Pos = i;
    
    for (int j = i + 1; j < Size; j++)
      if (Min > Array[j])
      {
        Min = Array[j];
        Pos = j;        
      }
      
    if (Pos != i)
    {
      Array[Pos] = Array[i];
      Array[i] = Min;
    }
  }
}

void OnStart()
{
  A Array[3] = {{2, 2}, {3,1}, {1, 3}};
  
  ArrayPrint(Array);
  
  // Сортировка по правилу A
  Sort<A, A>(Array); 
  ArrayPrint(Array);
  
  // Сортировка по правилу B
  Sort<A, B>(Array);  
  ArrayPrint(Array);
}


Risultato

    [a] [b]
[0]   2   2
[1]   3   1
[2]   1   3
    [a] [b]
[0]   1   3
[1]   2   2
[2]   3   1
    [a] [b]
[0]   3   1
[1]   2   2
[2]   1   3


Questa è probabilmente una bicicletta antica.

 
fxsaber:

La capacità di sostituire gli operatori delle strutture di tipo base permette una certa flessibilità in alcune situazioni.

ci sono alcuni punti. in mql, < operator deve necessariamente essere un metodo di classe/struttura.

Questo significa che non può essere impostato per le strutture incorporate o per quelle immutabili.

Questo può essere migliorato un po' aggiungendo una funzione di confronto dei template, che per default chiamerà l'operatore <

UPD: scrivo l'operatore < ovunque perché di solito è sovraccaricato piuttosto che >, non è rigoroso, ma è generalmente accettato
 
TheXpert:

Ci sono alcuni punti. in mql, l'operatore < deve essere un metodo della classe/struttura.

Significa che non può essere impostato per strutture incorporate o per strutture immutabili.

// Вспомогательная структура для изменения правила сортировки
struct MQLTICK_BID : MqlTick
{
  // Сортировка по времени
  bool operator <( const MqlTick& Value ) const 
  {
    return(this.bid < Value.bid);
  }
};

// Простая сортировка
template <typename T1, typename T2> // T2 - по какому правилу сортируем
void Sort( T1 &Array[] )
{
  const int Size = ArraySize(Array);
  
  for (int i = 0; i < Size - 1; i++)
  {
    T2 Min = Array[i];
    int Pos = i;
    
    for (int j = i + 1; j < Size; j++)
      if (Min < Array[j])
      {
        Min = Array[j];
        Pos = j;        
      }
      
    if (Pos != i)
    {
      Array[Pos] = Array[i];
      Array[i] = Min;
    }
  }
}

void OnStart()
{
  MqlTick Ticks[];
  
  CopyTicks(_Symbol, Ticks, COPY_TICKS_ALL, 0, 5);
  
  ArrayPrint(Ticks);
  
  // Сортировка по правилу MQLTICK_BID
  Sort<MqlTick, MQLTICK_BID>(Ticks); 
  ArrayPrint(Ticks);
}


Risultato

                 [time]   [bid]   [ask]  [last] [volume]    [time_msc] [flags] [volume_real]
[0] 2018.10.11 23:59:55 1.09115 1.09354 0.00000        0 1539302395303       6       0.00000
[1] 2018.10.11 23:59:56 1.09132 1.09348 0.00000        0 1539302396037       6       0.00000
[2] 2018.10.11 23:59:56 1.09131 1.09353 0.00000        0 1539302396302       6       0.00000
[3] 2018.10.11 23:59:59 1.09135 1.09354 0.00000        0 1539302399458       6       0.00000
[4] 2018.10.11 23:59:59 1.09139 1.09378 1.09260        0 1539302399989      14       0.00000
                 [time]   [bid]   [ask]  [last] [volume]    [time_msc] [flags] [volume_real]
[0] 2018.10.11 23:59:59 1.09139 1.09378 1.09260        0 1539302399989      14       0.00000
[1] 2018.10.11 23:59:59 1.09135 1.09354 0.00000        0 1539302399458       6       0.00000
[2] 2018.10.11 23:59:56 1.09132 1.09348 0.00000        0 1539302396037       6       0.00000
[3] 2018.10.11 23:59:56 1.09131 1.09353 0.00000        0 1539302396302       6       0.00000
[4] 2018.10.11 23:59:55 1.09115 1.09354 0.00000        0 1539302395303       6       0.00000


Questo modo può essere migliorato un po', aggiungendo una funzione di confronto dei template, che chiamerà di default l'operatore <

Se usate typedef, allora dovete definire una funzione di ordinamento non solo per le strutture, ma anche per i tipi numerici standard. O forse non capisco di cosa stai parlando.

Motivazione: