mql5 언어의 특징, 미묘함 및 작업 방법 - 페이지 104

 
안드레이 카팀리안스키 :

Market Watch에는 몇 개의 상품이 있습니까?

61.

 
fxsaber :

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 // 그래픽 플롯

Indicator_type을 1에서 6으로 지정하면 표시기가 6개의 그래픽 플롯에 대해 컬러 라인을 그려야 한다는 것을 이해한다는 것을 올바르게 이해하고 있습니까?

#속성 표시기_유형1 DRAW_COLOR_LINE

#속성 표시기_유형2 DRAW_COLOR_LINE

#속성 표시기_유형3 DRAW_COLOR_LINE

#속성 표시기_유형4 DRAW_COLOR_LINE

#속성 표시기_유형5 DRAW_COLOR_LINE

#속성 표시기_유형6 DRAW_COLOR_LINE


// =====

SetIndexBuffer(0,upper_line,INDICATOR_DATA); // 첫 번째 데이터 버퍼

SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX); // 색상 데이터를 위한 두 번째 버퍼


PlotIndexSetString(0,PLOT_LABEL,"상단 라인"); // 첫 번째 버퍼의 속성 변경

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,"평균선"); // 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 // 그래픽 플롯

Indicator_type을 1에서 6으로 지정하면 표시기가 6개의 그래픽 플롯에 대해 컬러 라인을 그려야 한다는 것을 이해한다는 것을 올바르게 이해하고 있습니까?

#속성 표시기_유형1 DRAW_COLOR_LINE

#속성 표시기_유형2 DRAW_COLOR_LINE

#속성 표시기_유형3 DRAW_COLOR_LINE

#속성 표시기_유형4 DRAW_COLOR_LINE

#속성 표시기_유형5 DRAW_COLOR_LINE

#속성 표시기_유형6 DRAW_COLOR_LINE


// =====

SetIndexBuffer(0,upper_line,INDICATOR_DATA); // 첫 번째 데이터 버퍼

SetIndexBuffer(1,upper_line_color,INDICATOR_COLOR_INDEX); // 색상 데이터를 위한 두 번째 버퍼


PlotIndexSetString(0,PLOT_LABEL,"상단 라인"); // 첫 번째 버퍼의 속성 변경

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,"평균선"); // 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 빌드 에서는 버그가 기적적으로 사라졌습니다. 나는 그들을 찾기 위해 롤백해야하는지 또는이 장소에서 무언가가 방금 수정되었는지조차 모릅니다 ...

오류는 사라졌지만 이벤트 대기열의 문제는 사라지지 않았습니다. 몇 시간의 작동 후 터미널은 95%에서 CPU를 로드하기 시작합니다. 그리고 틱을 건너 뛰었다는 내용이 있습니다.

 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 , 19x 빌드에서 ChartEvents에 변경 사항이 있습니까? 문제를 재현하고 있습니까?

 
안드레이 카팀리안스키 :

오류는 사라졌지만 이벤트 대기열의 문제는 사라지지 않았습니다. 몇 시간의 작동 후 터미널은 95%에서 CPU를 로드하기 시작합니다. 그리고 틱을 건너 뛰었다는 내용이 있습니다.

@Slava , 19x 빌드에서 ChartEvents에 변경 사항이 있습니까? 문제를 재현하고 있습니까?

다음은 터미널 작업 15시간 후 리소스 모니터링의 모습입니다(스파이가 이벤트를 보내는 최소 빈도는 500ms임).

출시 후 몇 시간이 지났지만 CPU 사용량은 0에 가깝습니다.

 
안드레이 카팀리안스키 :

다음은 터미널 작업 15시간 후 리소스 모니터링의 모습입니다(스파이가 이벤트를 보내는 최소 빈도는 500ms임).

출시 후 몇 시간이 지났지만 CPU 사용량은 0에 가깝습니다.

빌드 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에서 < 연산자 는 class\structure 의 메서드 여야 합니다.

이것은 빌트인 구조에 대해 설정할 수 없음을 의미합니다. 글쎄, 또는 불변을 위해.

이 방법은 기본적으로 < 연산자를 호출하는 비교 템플릿 함수를 추가하여 약간 개선할 수 있습니다.

UPD: 일반적으로 오버로드하고 >가 아니기 때문에 < 연산자를 어디에나 씁니다. 이것은 엄격하지는 않지만 일반적으로 허용됩니다.
 
더엑스퍼트 :

몇 가지 점이 있습니다. mql에서 < 연산자 는 class\structure 의 메서드 여야 합니다.

이것은 내장 구조에 대해 설정할 수 없음을 의미합니다. 글쎄, 또는 불변을 위해.

 // Вспомогательная структура для изменения правила сортировки
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를 사용하는 경우 구조뿐만 아니라 표준 숫자 유형에 대해서도 정렬 함수를 정의해야 합니다. 아니면 무슨 말인지 이해가 안 가네요.

사유: