mql5语言的特点、微妙之处以及技巧 - 页 104

 
安德烈-哈蒂姆连斯基

在市场审查中,有多少文书?

61.

 
fxsaber:

Build 1907 中,这些错误奇迹般地消失了。我甚至不知道是否要回滚去找它们,或者这个地方的某些东西刚刚被修复了......。

 

关于指标构建的问题

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

可以使用多少种颜色的缓冲器?

缓冲区之间是如何连接的?

#property indicator_buffers 12 // 声明总共有12个缓冲区

#property indicator_plots 6 //graphical constructions

我的理解是否正确,指定指标类型1到6,指标将理解为应该为6个图形图绘制颜色线?

#属性 indicator_type1 DRAW_COLOR_LINE

#属性 indicator_type2 DRAW_COLOR_LINE

#属性 indicator_type3 DRAW_COLOR_LINE

#属性 indicator_type4 DRAW_COLOR_LINE

#属性 indicator_type5 DRAW_COLOR_LINE

#属性 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"); // 改变SetIndexBuffer(2,awera_line,INDICATOR_DATA)的缓冲器属性。

PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle); // 为SetIndexBuffer(2,awera_line,INDICATOR_DATA)改变缓冲区的属性。

PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth); // 为SetIndexBuffer(2,awera_line,INDICATOR_DATA)改变缓冲区的属性。

PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2); // 改变SetIndexBuffer(2,awera_line,INDICATOR_DATA)的缓冲区的属性。

PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp); //改变SetIndexBuffer(2,awera_line,INDICATOR_DATA)的缓冲区的属性。

PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw); // 改变SetIndexBuffer(2,awera_line,INDICATOR_DATA)的缓冲区的属性。

 
弗拉基米尔-帕斯图沙克

关于指标构建的问题

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

可以使用多少种颜色的缓冲器?

缓冲区之间是如何连接的?

#property indicator_buffers 12 // 声明总共有12个缓冲区

#property indicator_plots 6 //graphical constructions

我的理解是否正确,指定指标类型1到6,指标将理解为应该为6个图形图绘制颜色线?

#属性 indicator_type1 DRAW_COLOR_LINE

#属性 indicator_type2 DRAW_COLOR_LINE

#属性 indicator_type3 DRAW_COLOR_LINE

#属性 indicator_type4 DRAW_COLOR_LINE

#属性 indicator_type5 DRAW_COLOR_LINE

#属性 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); // Fourth buffer of colors


PlotIndexSetString(1,PLOT_LABEL, "Average Line"); // 改变SetIndexBuffer(2,awera_line,INDICATOR_DATA)的缓冲器属性。

PlotIndexSetInteger(1,PLOT_LINE_STYLE,AverageStyle); // 为SetIndexBuffer(2,awera_line,INDICATOR_DATA)改变缓冲区的属性。

PlotIndexSetInteger(1,PLOT_LINE_WIDTH,AverageWidth); // 为SetIndexBuffer(2,awera_line,INDICATOR_DATA)改变缓冲区的属性。

PlotIndexSetInteger(1,PLOT_COLOR_INDEXES,2); // 改变SetIndexBuffer(2,awera_line,INDICATOR_DATA)的缓冲区的属性。

PlotIndexSetInteger(1,PLOT_LINE_COLOR,0,AverageTrendUp); //改变SetIndexBuffer(2,awera_line,INDICATOR_DATA)的缓冲区的属性。

PlotIndexSetInteger(1,PLOT_LINE_COLOR,1,AverageTrendDw); // 改变SetIndexBuffer(2,awera_line,INDICATOR_DATA)的缓冲区的属性。

你最好为你的问题建立一个单独的分支。这个分支是关于功能的,这里不应该有任何讨论。

为了更好地理解绘图的原理,逐步实现功能。你已经建立了一条线--检查其功能,添加下一条线。

每个图形系列(在这里是指颜色线)只能有一个颜色缓冲区。每个缓冲区可以包含很多颜色。

 
安德烈-哈蒂姆连斯基

1907年的版本 中,这些虫子奇迹般地消失了。我甚至不知道是否要回滚去找它们,或者这个地方的某些东西刚刚被修复......。

错误消失了,但事件队列的问题没有消失。几个小时后,终端开始将CPU的负荷提高到95%。而且有东西告诉我,蜱虫被跳过了。

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,在19xx年的构建中,ChartEvent有什么变化吗?这个问题是否在你的构建中重现了?

 
安德烈-哈蒂姆连斯基

错误已经消失了,但事件队列的问题没有消失。经过几个小时的运行,终端开始将CPU的负荷提高到95%。而且有东西告诉我,虱子不见了。

@Slava,在19xx年的构建中,ChartEvent有什么变化吗?你的问题是否重现了?

这是终端工作15小时后的资源监测情况(间谍事件发送的最小频率为500毫秒)。

尽管在启动后的几个小时内,CPU负载接近于0。

 
安德烈-哈蒂姆连斯基

这是终端运行15小时后的资源监测情况(最小的间谍软件事件发送率为500ms)。

尽管在启动后的几个小时内,CPU负载接近于0。

Bild 1908 - 没有变化。

 

替换基本类型结构运算符的能力允许在某些情况下有灵活性。

作为一个例子,这里是对一个 结构数组 进行自定义排序 的技术之一

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


结果

    [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


这可能是一辆古老的自行车。

 
fxsaber:

替换基本类型结构的操作者的能力允许在某些情况下有灵活性。

有几点:在Mql中,<操作符必须是类/结构的一个方法

这意味着它不能被设置为嵌入式结构,也不能被设置为不可变的结构。

这一点可以通过添加一个模板比较函数来改进,该函数默认会调用<操作符

UPD:我在任何地方都写<操作符,因为它通常是重载的,而不是>,这并不严格,但它被普遍接受。
 
TheXpert

在mql中,<操作符必须是类/结构的一个方法

这意味着它不能为嵌入式结构 设置。 或为不可变的结构设置。

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


结果

                 [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


这种方式可以改进一下,通过添加一个模板比较函数,默认会调用<操作符

如果你使用typedef,那么你不仅要为结构定义一个排序函数,也要为标准数字类型定义一个排序函数。或者,也许我不明白你在说什么。