Características da linguagem mql5, subtilezas e técnicas - página 104

 
Andrey Khatimlianskii:

Quantos instrumentos na análise do mercado?

61.

 
fxsaber:

Na construção de 1907, os insectos desapareceram milagrosamente. Nem sei se devo voltar atrás para encontrá-los, ou se algo neste lugar acabou de ser consertado...

 

Pergunta sobre a construção 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);

Quantos tampões de cor podem ser usados?

Como é que os amortecedores estão ligados entre si?

#property indicator_buffers 12 // Declare um total de 12 buffers

#property indicator_plots 6 // construções gráficas

Entendo correctamente, que especificando indicador_tipo 1 a 6, o indicador irá entender que as linhas de cor devem ser desenhadas 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); // Primeiro buffer para dados

SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX); // Segundo buffer para dados de cor


PlotIndexSetString(0,PLOT_LABEL, "Linha Superior"); // Alterar propriedades do primeiro buffer

PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);// propriedades de alteração do primeiro buffer

PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);// propriedades de alteração do primeiro buffer

PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);// alterar propriedades do primeiro buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp);// alterar propriedades do primeiro buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw);// alterar propriedades do primeiro buffer


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

SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX); // Quarto buffer de cores


PlotIndexSetString(1,PLOT_LABEL, "Linha Média"); // Alterar propriedades de buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle); // Alterar propriedades do buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth); // Alterar propriedades do buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2); // Alterar propriedades do buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp); // Alterar propriedades do buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw); // Alterar propriedades do buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

 
Vladimir Pastushak:

Pergunta sobre a construção 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);

Quantos tampões de cor podem ser usados?

Como é que os amortecedores estão ligados entre si?

#property indicator_buffers 12 // Declare um total de 12 buffers

#property indicator_plots 6 // construções gráficas

Se entendi correctamente, que especificando indicador_tipo 1 a 6, o indicador vai entender que as linhas de cor devem ser desenhadas 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); // Primeiro buffer para dados

SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX); // Segundo buffer para dados de cor


PlotIndexSetString(0,PLOT_LABEL, "Linha Superior"); // Alterar propriedades do primeiro buffer

PlotIndexSetInteger(0,PLOT_LINE_STYLE,UpperStyle);// propriedades de alteração do primeiro buffer

PlotIndexSetInteger(0,PLOT_LINE_WIDTH,UpperWidth);// propriedades de alteração do primeiro buffer

PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,2);// alterar propriedades do primeiro buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,UpperTrendUp);// alterar propriedades do primeiro buffer

PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,UpperTrendDw);// alterar propriedades do primeiro buffer


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

SetIndexBuffer(3,awera_line_color,INDICATOR_COLOR_INDEX); // Quarto buffer de cores


PlotIndexSetString(1,PLOT_LABEL, "Linha Média"); // Alterar propriedades de buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle); // Alterar propriedades do buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth); // Alterar propriedades do buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2); // Alterar propriedades do buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp); // Alterar propriedades do buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw); // Alterar propriedades do buffer para SetIndexBuffer(2,awera_line,INDICATOR_DATA);

É melhor criar um ramo separado para a sua pergunta. Este ramo é sobre características, não deve haver nenhuma discussão aqui.

Para compreender melhor o princípio do desenho, implemente a funcionalidade de forma incremental. Você construiu uma linha - verifique sua funcionalidade, adicione a próxima linha.

Cada série gráfica (neste caso uma linha de cor) pode ter apenas um buffer de cor. Cada tampão pode conter muitas cores.

 
Andrey Khatimlianskii:

Na construção de 1907, os insectos desapareceram miraculosamente. Nem sei se devo voltar atrás para encontrá-los, ou se algo neste lugar acabou de ser consertado...

Os erros desapareceram, mas os problemas com a fila de eventos não. Após algumas horas, o terminal começa a carregar a CPU até 95%. E algo me diz que as carraças são ignoradas.

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, algo mudou no ChartEvent em 19xx constrói? O problema está reproduzido nas suas construções?

 
Andrey Khatimlianskii:

Os erros desapareceram, mas os problemas de fila de eventos não. Após algumas horas de operação, o terminal começa a carregar a CPU a 95%. E algo me diz que faltam carrapatos.

@Slava, algo mudou no ChartEvent em 19xx constrói? O seu problema está reproduzido?

Este é o aspecto do monitoramento de recursos após 15 horas de trabalho do terminal (a freqüência mínima de envio de eventos de espionagem é de 500 ms):

Embora a carga da CPU esteja próxima de 0 durante várias horas após a inicialização.

 
Andrey Khatimlianskii:

Este é o aspecto do monitoramento de recursos após 15 horas de operação do terminal (a taxa mínima de envio de eventos de spyware é de 500ms):

Embora a carga da CPU esteja próxima de 0 durante algumas horas após a inicialização.

Bild 1908 - sem alterações.

 

A capacidade de substituir os operadores da estrutura tipo base permite a flexibilidade em algumas situações.

Como exemplo, aqui está uma das técnicas de classificação personalizada de um conjunto de estruturas

// Основная структура
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 é provavelmente uma bicicleta antiga.

 
fxsaber:

A capacidade de substituir operadores de estruturas do tipo base permite flexibilidade em algumas situações.

há alguns pontos. em mql, < operador deve ser necessariamente um método de classe/estrutura.

Isto significa que não pode ser definido para estruturas embutidas, ou para estruturas imutáveis.

Isto pode ser um pouco melhorado adicionando uma função de comparação de modelos, que por padrão chamará o operador <

UPD: Eu escrevo < operador em todo lugar porque normalmente é sobrecarregado em vez de >, não é rigoroso, mas é geralmente aceite
 
TheXpert:

há alguns pontos. em mql, o < operador tem de ser um método da classe/estrutura.

Significa que não pode ser definido para estruturas embutidas. Ou para estruturas imutáveis.

// Вспомогательная структура для изменения правила сортировки
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 pode ser um pouco melhorada, adicionando uma função de comparação de modelos, que por padrão chamará o operador <

Se for utilizado typedef, é necessário definir uma função de ordenação não só para estruturas, mas também para tipos numéricos standard. Ou talvez eu não entenda do que estás a falar.

Razão: