Características del lenguaje mql5, sutilezas y técnicas - página 104

 
Andrey Khatimlianskii:

¿Cuántos instrumentos hay en la revisión del mercado?

61.

 
fxsaber:

En la compilación 1907 los errores han desaparecido milagrosamente. Ni siquiera sé si hay que retroceder para encontrarlos, o si se acaba de arreglar algo en este sitio...

 

Pregunta sobre la construcción de indicadores

#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);

¿Cuántos tampones de color se pueden utilizar?

¿Cómo se vinculan los topes entre sí?

#property indicator_buffers 12 // Declarar un total de 12 buffers

#property indicator_plots 6 // construcciones gráficas

¿Entiendo correctamente que especificando indicator_type 1 a 6, el indicador entenderá que se deben dibujar líneas de color para 6 gráficos?

#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); // Primer buffer para datos

SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX); // Segundo buffer para datos de color


PlotIndexSetString(0,PLOT_LABEL, "Upper Line"); // Cambiar las propiedades del primer buffer

PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);// cambiar las propiedades del primer buffer

PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);//cambiar las propiedades del primer buffer

PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);// cambiar las propiedades del primer buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp);// cambiar las propiedades del primer buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw);// cambiar las propiedades del primer buffer


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

SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX); // Cuarto buffer de colores


PlotIndexSetString(1,PLOT_LABEL, "Average Line"); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

 
Vladimir Pastushak:

Pregunta sobre la construcción de indicadores

#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);

¿Cuántos tampones de color se pueden utilizar?

¿Cómo se vinculan los topes entre sí?

#property indicator_buffers 12 // Declarar un total de 12 buffers

#property indicator_plots 6 // construcciones gráficas

¿Entiendo correctamente que especificando indicator_type 1 a 6, el indicador entenderá que se deben dibujar líneas de color para 6 gráficos?

#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); // Primer buffer para datos

SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX); // Segundo buffer para datos de color


PlotIndexSetString(0,PLOT_LABEL, "Upper Line"); // Cambiar las propiedades del primer buffer

PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);// cambiar las propiedades del primer buffer

PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);//cambiar las propiedades del primer buffer

PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);// cambiar las propiedades del primer buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp);// cambiar las propiedades del primer buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw);// cambiar las propiedades del primer buffer


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

SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX); // Cuarto buffer de colores


PlotIndexSetString(1,PLOT_LABEL, "Average Line"); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw); // Cambiar las propiedades del buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

Será mejor que crees una rama separada para tu pregunta. Esta rama es sobre características, no debería haber discusiones aquí.

Para comprender mejor el principio del dibujo, implemente la funcionalidad de forma incremental. Has construido una línea - comprueba su funcionalidad, añade la siguiente.

Cada serie gráfica (en este caso una línea de color) sólo puede tener un búfer de color. Cada búfer puede contener muchos colores.

 
Andrey Khatimlianskii:

En la compilación de 1907, los errores han desaparecido milagrosamente. Ni siquiera sé si hay que retroceder para encontrarlos, o si se acaba de arreglar algo en este sitio...

Los errores desaparecieron, pero los problemas con la cola de eventos no. Después de unas horas, el terminal empieza a cargar la CPU hasta el 95%. Y algo me dice que las garrapatas se saltan.

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, ¿ha cambiado algo en ChartEvent en las builds 19xx? ¿Se reproduce el problema en tus construcciones?

 
Andrey Khatimlianskii:

Los errores han desaparecido, pero los problemas de la cola de eventos no. Tras unas horas de funcionamiento, el terminal empieza a cargar la CPU al 95%. Y algo me dice que faltan garrapatas.

@Slava, ¿ha cambiado algo en ChartEvent en las builds 19xx? ¿Se reproduce su problema?

Este es el aspecto de la monitorización de los recursos tras 15 horas de trabajo del terminal (la frecuencia mínima de envío de eventos del espía es de 500 ms):

Aunque la carga de la CPU es cercana a 0 durante varias horas después del arranque.

 
Andrey Khatimlianskii:

Este es el aspecto de la monitorización de recursos después de 15 horas de funcionamiento del terminal (la tasa mínima de envío de eventos de spyware es de 500ms):

Aunque la carga de la CPU es cercana a 0 durante unas horas después del arranque.

Bild 1908 - sin cambios.

 

La posibilidad de sustituir los operadores de la estructura del tipo base permite la flexibilidad en algunas situaciones.

A modo de ejemplo, he aquí una de las técnicas de ordenación personalizada de una matriz de estructuras

// Основная структура
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);
}


Resultado

    [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


Esta es probablemente una bicicleta antigua.

 
fxsaber:

La posibilidad de reemplazar los operadores de las estructuras de tipo base permite la flexibilidad en algunas situaciones.

hay algunos puntos. en mql, el operador < debe ser necesariamente un método de clase/estructura.

Esto significa que no puede establecerse para las estructuras incrustadas, ni para las inmutables.

Esto se puede mejorar un poco añadiendo una función de comparación de plantillas, que por defecto llamará al operador <

UPD: Escribo el operador < en todas partes porque suele estar sobrecargado en lugar de >, no es estricto, pero es generalmente aceptado
 
TheXpert:

hay algunos puntos. en mql, el operador < tiene que ser un método de la clase/estructura.

Significa que no se puede establecer para las estructuras incrustadas. O para las estructuras inmutables.

// Вспомогательная структура для изменения правила сортировки
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);
}


Resultado

                 [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


Esta forma se puede mejorar un poco, añadiendo una función de comparación de plantillas, que por defecto llamará al operador <

Si se utiliza typedef, hay que definir una función de ordenación no sólo para las estructuras, sino también para los tipos numéricos estándar. O tal vez no entiendo de qué estás hablando.

Razón de la queja: