초보자의 질문 MQL5 MT5 MetaTrader 5 - 페이지 919

 
Artyom Trishkin :

지표를 처음부터 끝까지(최신 기록 데이터에서 최신 데이터까지 - 현재까지) 계산 합니다. 그리고 이것은 시계열에서와 같이 인덱싱에 대해 말합니다. 이것은 배열이 그에 따라 인덱싱되어야 함을 의미합니다.

그러면 작동하지 않는 것은 무엇입니까?

예, 모든 것이 MQL4의 MQL5에 있는 내 포트에서 일대일로 작동하지만 ArraySetAsSeries()로 인해 코드가 보기 흉하므로 묻습니다.

여기에 두 코드가 있습니다

글쎄, MT5에 대한이 지표를 예시적으로 쓰는 법을 가르쳐주세요 !!! - 내 코드와 포인트가 아름답지 않습니다! )))

추신 MT5에서 지표를 작성하는 방법을 전혀 기억하지 못하고 40 분 만에 도움을 받아 앉아서 멍청하게 다시 작성했지만 결과는 ... C 등급에 대한 IMHO (((

파일:
PTL.mq4  8 kb
PTL.mq5  13 kb
 
Igor Makanu :

예, 모든 것이 MQL4의 MQL5에 있는 내 포트에서 일대일로 작동하지만 ArraySetAsSeries()로 인해 코드가 보기 흉하므로 묻습니다.

여기에 두 코드가 있습니다

글쎄, MT5에 대한이 지표를 예시적으로 쓰는 법을 가르쳐주세요 !!! - 내 코드와 포인트가 아름답지 않습니다! )))

역방향으로 루핑할 때 배열을 시계열로 만들어야 합니다. 그렇지 않으면 루프의 버퍼 인덱싱이 필요한 데이터의 인덱싱과 일치하지 않습니다. 표시기 버퍼 배열의 루프 인덱스는 처음부터 끝까지 이동하며, open[], high[], low[], close [] 및 나머지 - 끝에서 시작까지. 또는 루프를 뒤집어 open[], high[], low[], close[]의 배열 인덱싱 과 일치시키고 나머지는 버퍼 인덱싱과 일치시키십시오. 이는 더 복잡합니다.

우화를 원하고 더 명확하다면 여기에 우화가 있습니다.

당신은 기찻길에 서서 두 대의 기차를 바라보고 있습니다. 그들은 같은 방향으로 이동합니다 - 둘 다 왼쪽에서 오른쪽(ArraySetAsSeries(array,true) - 첫 번째 기차 및 제한에서 0까지 순환 - 두 번째 기차),
서로를 향해 가거나 - (ArraySetAsSeries(array,false) - 오른쪽에서 왼쪽으로 - 첫 번째 기차, 한계에서 0까지의 주기 - 왼쪽에서 오른쪽으로 - 두 번째 기차)

그리고, 예: 코드를 보지 않았습니다. 다운로드하고 싶지 않고, 직접 저장하고(이미 포럼에 불필요한 코드가 많이 있음), 서로 비교하고 ...

메시지의 코드에 하나와 두 번째를 넣는 것이 더 쉬웠습니다. 그러면 무엇이 무엇인지 즉시 알 수 있습니다.

 
Artyom Trishkin :

음, 또는 더 복잡한 배열 open[], high[], low[], close[] 및 기타 배열의 인덱싱 과 일치하도록 루프를 반대로 합니다.

나는 오늘 저녁 내내 뒤집어 놓았고 이제 내 인내심은 끝났습니다 (((

내가 문제를 이해하는 한 :

- MT5에서 표시기 버퍼로 할당된 배열은 기본적으로 왼쪽에서 오른쪽으로 인덱싱됩니다.

- MT5 시계열에서   OnCalculate() 에서 사용할 수 있는 open[], high[], low[], close[] 는 항상 오른쪽에서 왼쪽으로 인덱싱됩니다.

- 즉, 단락 1과 2를 기반으로 기록의 끝에서 0 막대까지 지표를 계산하려면 다음을 수행해야 합니다.

a) 또는 버퍼 배열 인덱싱 재할당

b) 또는 배열 요소의 번호 매기기가 왼쪽에서 오른쪽으로, 다른 하나에서는 오른쪽에서 왼쪽으로 다시 계산되는 루프를 만듭니다.

 for (i=limit;i>= 0 ;i--)
     {
      BufBarsBuffer1[limit - i] = open[i];
      ...
      }


저것들. 내 질문에 대한 아름다운 해결책이 없습니까? 옵션 a) - 내 소스에 구현됨, 옵션 b) - 추가 계산을 할 이유가 없습니다.

출처:

MT5:

 //+------------------------------------------------------------------+
//|                                          Perfect_Trend_Lines.mq5 |
//|                                                            IgorM |
//|                                                                  |
//+------------------------------------------------------------------+
#property version    "1.00"
#property indicator_chart_window
#property indicator_buffers 9
#property indicator_plots    5
//--- plot BufBars
#property indicator_label1    "BufBars"
#property indicator_type1    DRAW_COLOR_BARS
#property indicator_color1    clrRed , clrAqua , clrNONE
#property indicator_style1    STYLE_SOLID
#property indicator_width1    3
//--- plot BufASELL
#property indicator_label2    "BufASELL"
#property indicator_type2    DRAW_ARROW
#property indicator_color2    clrBlue
#property indicator_style2    STYLE_SOLID
#property indicator_width2    5
//--- plot BufABUY
#property indicator_label3    "BufABUY"
#property indicator_type3    DRAW_ARROW
#property indicator_color3    clrRed
#property indicator_style3    STYLE_SOLID
#property indicator_width3    5
//--- plot BufLSELL
#property indicator_label4    "BufLSELL"
#property indicator_type4    DRAW_LINE
#property indicator_color4    clrBlue
#property indicator_style4    STYLE_SOLID
#property indicator_width4    2
//--- plot BufLBUY
#property indicator_label5    "BufLBUY"
#property indicator_type5    DRAW_LINE
#property indicator_color5    clrRed
#property indicator_style5    STYLE_SOLID
#property indicator_width5    2
//--- input parameters
input int SlowLength         = 7 ; //Slow length
input int SlowPipDisplace    = 0 ; //Slow pip displace
input int FastLength         = 3 ; //Fast length
input int FastPipDisplace    = 0 ; //Fast pip displace
//--- indicator buffers
double          BufBarsBuffer1[];
double          BufBarsBuffer2[];
double          BufBarsBuffer3[];
double          BufBarsBuffer4[];
double          BufBarsColors[];
double          BufASELLBuffer[];
double          BufABUYBuffer[];
double          BufLSELLBuffer[];
double          BufLBUYBuffer[];
static int trend= 0 ;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- indicator buffers mapping
   SetIndexBuffer ( 0 ,BufBarsBuffer1, INDICATOR_DATA );
   SetIndexBuffer ( 1 ,BufBarsBuffer2, INDICATOR_DATA );
   SetIndexBuffer ( 2 ,BufBarsBuffer3, INDICATOR_DATA );
   SetIndexBuffer ( 3 ,BufBarsBuffer4, INDICATOR_DATA );
   SetIndexBuffer ( 4 ,BufBarsColors, INDICATOR_COLOR_INDEX );
   SetIndexBuffer ( 5 ,BufASELLBuffer, INDICATOR_DATA );
   SetIndexBuffer ( 6 ,BufABUYBuffer, INDICATOR_DATA );
   SetIndexBuffer ( 7 ,BufLSELLBuffer, INDICATOR_DATA );
   SetIndexBuffer ( 8 ,BufLBUYBuffer, INDICATOR_DATA );
   for ( int i= 0 ;i< 9 ;i++)
     {
       PlotIndexSetInteger (i, PLOT_DRAW_BEGIN ,FastLength+ 1 );
       PlotIndexSetDouble (i, PLOT_EMPTY_VALUE , 0.0 );
     }
   ArraySetAsSeries (BufBarsBuffer1, true );
   ArraySetAsSeries (BufBarsBuffer2, true );
   ArraySetAsSeries (BufBarsBuffer3, true );
   ArraySetAsSeries (BufBarsBuffer4, true );
   ArraySetAsSeries (BufBarsColors, true );
   ArraySetAsSeries (BufABUYBuffer, true );
   ArraySetAsSeries (BufASELLBuffer, true );
   ArraySetAsSeries (BufLBUYBuffer, true );
   ArraySetAsSeries (BufLSELLBuffer, true );
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger ( 1 , PLOT_ARROW , 234 );
   PlotIndexSetInteger ( 2 , PLOT_ARROW , 233 );
   PlotIndexSetInteger ( 1 , PLOT_ARROW_SHIFT ,- 20 );
   PlotIndexSetInteger ( 2 , PLOT_ARROW_SHIFT , 20 );
   trend= 0 ;
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate ( const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[])
  {
//---
   int i,limit;
   double thigh1,tlow1,thigh2,tlow2,trendUp,trendDn;
   ArraySetAsSeries (open, true ); ArraySetAsSeries (high, true ); ArraySetAsSeries (low, true ); ArraySetAsSeries (close, true );
   if (prev_calculated== 0 )
     {
      limit=rates_total- 1 ;
      BufLSELLBuffer[limit]=high[limit];
      BufLBUYBuffer[limit]=low[limit];
      limit--;
     }
   else limit=rates_total-prev_calculated+ 1 ;
   for (i=limit;i>= 0 ;i--)
     {
      thigh1= high[ iHighest ( NULL , 0 , MODE_HIGH ,SlowLength,i)]+SlowPipDisplace * _Point ;
      tlow1 = low[ iLowest ( NULL , 0 , MODE_LOW ,SlowLength,i)]-SlowPipDisplace * _Point ;
      thigh2= high[ iHighest ( NULL , 0 , MODE_HIGH ,FastLength,i)]+FastPipDisplace * _Point ;
      tlow2 = low[ iLowest ( NULL , 0 , MODE_LOW ,FastLength,i)]-FastPipDisplace * _Point ;
       if (close[i]>BufLBUYBuffer[i+ 1 ])  trendUp=tlow1;   else trendUp=thigh1;
       if (close[i]>BufLSELLBuffer[i+ 1 ]) trendDn=tlow2;   else trendDn=thigh2;
      BufLSELLBuffer[i]= trendDn;
      BufLBUYBuffer[i] = trendUp;
      BufBarsBuffer1[i] = 0.0 ;
      BufBarsBuffer2[i] = 0.0 ;
      BufBarsBuffer3[i] = 0.0 ;
      BufBarsBuffer4[i] = 0.0 ;
      BufBarsColors[i]  = 2 ;
       if (close[i]<trendUp && close[i]<trendDn)
        {
         BufBarsBuffer1[i] = open[i];
         BufBarsBuffer2[i] = high[i];
         BufBarsBuffer3[i] = low[i];
         BufBarsBuffer4[i] = close[i];
         BufBarsColors[i]  = 0 ;
        }
       if (close[i]>trendUp && close[i]>trendDn)
        {
         BufBarsBuffer1[i] = open[i];
         BufBarsBuffer2[i] = high[i];
         BufBarsBuffer3[i] = low[i];
         BufBarsBuffer4[i] = close[i];
         BufBarsColors[i]  = 1 ;
        }
       if (close[i]>trendUp && close[i]>trendDn && trend!= 1 )
        {
         BufABUYBuffer[i]=trendDn;
         BufASELLBuffer[i]= 0.0 ;
         trend= 1 ;
        }
       if (close[i]<trendUp && close[i]<trendDn && trend!= 2 )
        {
         BufASELLBuffer[i]=trendUp;
         BufABUYBuffer[i]= 0.0 ;
         trend= 2 ;
        }
     }
//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+------------------------------------------------------------------+

MT4:

 //+------------------------------------------------------------------+
//|                                            PerfecTrend Lines.mq4 |
//|                 Copyright © 2005-2007, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Aqua
#property indicator_color5 Blue
#property indicator_color6 Red

extern int SlowLength         = 7 ; // Slow length
extern int SlowPipDisplace    = 0 ; // Slow pip displace
extern int FastLength         = 3 ; // Fast length
extern int FastPipDisplace    = 0 ; // Fast pip displace

double Buf_NTLine1[],Buf_NTLine2[],Buf_NTBar1[],Buf_NTBar2[],Buf_NTSig1[],Buf_NTSig2[];
static int trend= 0 ;
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers ( 6 );
   IndicatorDigits ( MarketInfo ( Symbol (), MODE_DIGITS ));
   SetIndexStyle ( 0 , DRAW_LINE , STYLE_SOLID , 2 );
   SetIndexBuffer ( 0 ,Buf_NTLine1);
   SetIndexStyle ( 1 , DRAW_LINE , STYLE_SOLID , 2 );
   SetIndexBuffer ( 1 ,Buf_NTLine2);
   SetIndexStyle ( 2 , DRAW_HISTOGRAM , STYLE_SOLID , 2 );
   SetIndexBuffer ( 2 ,Buf_NTBar1);
   SetIndexStyle ( 3 , DRAW_HISTOGRAM , STYLE_SOLID , 2 );
   SetIndexBuffer ( 3 ,Buf_NTBar2);
   SetIndexStyle ( 4 , DRAW_ARROW , STYLE_DASH , 3 );
   SetIndexArrow ( 4 , 108 );
   SetIndexBuffer ( 4 ,Buf_NTSig1);
   SetIndexStyle ( 5 , DRAW_ARROW , STYLE_DASH , 3 );
   SetIndexArrow ( 5 , 108 );
   SetIndexBuffer ( 5 ,Buf_NTSig2);
   IndicatorShortName ( "NeuroTrend" );
   SetIndexLabel ( 0 , "NTLine1" );
   SetIndexLabel ( 1 , "NTLine2" );
   SetIndexLabel ( 2 , "NTBar1" );
   SetIndexLabel ( 3 , "NTBar2" );
   SetIndexLabel ( 4 , "NTSig1" );
   SetIndexLabel ( 5 , "NTSig2" );
   SetIndexDrawBegin ( 0 ,FastLength+ 1 );
   SetIndexDrawBegin ( 1 ,FastLength+ 1 );
   SetIndexDrawBegin ( 2 ,FastLength+ 1 );
   SetIndexDrawBegin ( 3 ,FastLength+ 1 );
   SetIndexDrawBegin ( 4 ,FastLength+ 1 );
   SetIndexDrawBegin ( 5 ,FastLength+ 1 );
   trend= 0 ;
   return ( 0 );
  }
//+------------------------------------------------------------------+
int deinit()
  {
   return ( 0 );
  }
//+------------------------------------------------------------------+
int start()
  {
   int i,limit;
   double thigh1,tlow1,thigh2,tlow2,trendA,trendB,trendUP,trendDN;
   if ( Bars <= FastLength) return ( 0 );
   if ( IndicatorCounted ()== 0 ) limit= Bars - 1 ;
   if ( IndicatorCounted ()> 0 ) limit= Bars - IndicatorCounted ()- 1 ;
   for (i=limit;i>= 0 ;i--)
     {
      thigh1= High [ iHighest ( NULL , 0 , MODE_HIGH ,SlowLength,i)]+SlowPipDisplace * Point ;
      tlow1 = Low [ iLowest ( NULL , 0 , MODE_LOW ,SlowLength,i)]-SlowPipDisplace * Point ;
      thigh2= High [ iHighest ( NULL , 0 , MODE_HIGH ,FastLength,i)]+FastPipDisplace * Point ;
      tlow2 = Low [ iLowest ( NULL , 0 , MODE_LOW ,FastLength,i)]-FastPipDisplace * Point ;
       if ( Close [i] > Buf_NTLine1[i+ 1 ]) trendA = tlow1; else trendA = thigh1;
       if ( Close [i] > Buf_NTLine2[i+ 1 ]) trendB = tlow2; else trendB = thigh2;
      Buf_NTLine1[i] = trendA;
      Buf_NTLine2[i] = trendB;

      trendUP = 0.0 ;
      trendDN = 0.0 ;
       if ( Close [i] < trendA && Close [i] < trendB) { trendUP = High [i]; trendDN = Low [i]; }
       if ( Close [i] > trendA && Close [i] > trendB) { trendUP = Low [i];  trendDN = High [i];}
      Buf_NTBar1[i] = trendUP;
      Buf_NTBar2[i] = trendDN;
       if ( Close [i] > trendB && Close [i] > trendA && trend != 1 ) { Buf_NTSig1[i] = trendB; Buf_NTSig2[i] = EMPTY_VALUE ; trend = 1 ; }
       if ( Close [i] < trendB && Close [i] < trendA && trend != 2 ) { Buf_NTSig2[i] = trendB; Buf_NTSig1[i] = EMPTY_VALUE ; trend = 2 ; }
     }
   return ( 0 );
  }
//+------------------------------------------------------------------+
 
Igor Makanu :

나는 오늘 저녁 내내 뒤집어 놓았고 이제 내 인내심은 끝났습니다 (((

내가 문제를 이해하는 한 :

- MT5에서 표시기 버퍼로 할당된 배열은 기본적으로 왼쪽에서 오른쪽으로 인덱싱됩니다.

- MT5 시계열에서   OnCalculate() 에서 사용할 수 있는 open[], high[], low[], close[] 는 항상 오른쪽에서 왼쪽으로 인덱싱됩니다.

- 즉, 단락 1과 2를 기반으로 기록의 끝에서 0 막대까지 지표를 계산하려면 다음을 수행해야 합니다.

a) 또는 버퍼 배열 인덱싱 재할당

b) 또는 배열 요소의 번호 매기기가 왼쪽에서 오른쪽으로, 다른 하나에서는 오른쪽에서 왼쪽으로 다시 계산되는 루프를 만듭니다.


저것들. 내 질문에 대한 아름다운 해결책이 없습니까? 옵션 a) - 내 소스에 구현됨, 옵션 b) - 추가 계산을 할 이유가 없습니다.

배열은 모두 오른쪽에서 왼쪽으로 인덱싱됩니다. 따라서 왼쪽에서 오른쪽으로의 순환에 완전히 대응하려면(그리고 한계에서 0까지 - 정확히 왼쪽에서 오른쪽으로) 사용된 모든 배열에 대해 필요한 인덱싱을 설정해야 합니다. OnInit()의 버퍼 , 사용 시계열 - OnCalculate().

또는 0에서 제한까지 주기를 수행합니다. 이는 mql4에서 mql5로 이식할 때 항상 쉽지는 않습니다.

따라서 이 경우 ArraySetAsSeries() 옵션이 더 유리합니다.

 
Artyom Trishkin :

배열은 모두 오른쪽에서 왼쪽으로 인덱싱됩니다. 따라서 왼쪽에서 오른쪽으로의 순환에 완전히 대응하려면(그리고 한계에서 0까지 - 정확히 왼쪽에서 오른쪽으로) 사용된 모든 배열에 대해 필요한 인덱싱을 설정해야 합니다. OnInit()의 버퍼 , 사용 시계열 - OnCalculate().

또는 0에서 제한까지 주기를 수행합니다. 이는 mql4에서 mql5로 이식할 때 항상 쉽지는 않습니다.

따라서 이 경우 ArraySetAsSeries() 옵션이 더 유리합니다.

글쎄, 봐, 내 코드에서 모든 ArraySetAsSeries()를 제거하고(첫 번째 줄의 Init() 및 OnCalculate()의 맨 위에 있음 ) 루프를 수정했습니다.

for(i=0;i<limit;i++)

이론상 모든 것이 맞아야 합니다! 하지만! 그래프가 달라서 이해가 안되네요!

파일:
1.jpg  747 kb
 
Igor Makanu :

글쎄, 봐, 내 코드에서 모든 ArraySetAsSeries()를 제거하고(첫 번째 줄의 Init() 및 OnCalculate()의 맨 위에 있음 ) 루프를 수정했습니다.

for(i=0;i<limit;i++)

이론상 모든 것이 맞아야 합니다! 하지만! 그래프가 달라서 이해가 안되네요!

더 어렵다고 합니다. 논리를 바꿔야 합니다. 사이클을 역전시키는 것만으로는 충분하지 않습니다.

다음은 하나의 작은 예입니다. 코드에는

Buf_NTLine1[i+ 1 ])

인덱스 i+1은 배열의 다른 인덱싱을 위해 어디로 갈까요?

그리고 많이 있습니다. IHighest() - 시작 및 계산... 하나의 인덱싱과 다른 인덱싱으로 시작하는 위치는 어디입니까?

등. ...

 
Artyom Trishkin :

그리고 많이 있습니다. IHighest() - 시작 및 계산... 하나의 인덱싱과 다른 인덱싱으로 시작하는 위치는 어디입니까?

팬케이크! 바로 그거죠! 잘했어요!!! 예, 재미가 있는 곳입니다!

네... MT5에는 많은 차이점이 있습니다. 너무 많은 검사와 모든 종류의 예측이 프로그래머의 머리에 떠오릅니다...

예, 여기에 또 다른 질문이 있습니다. 얼마 전에 MT5에서 Init()의 모든 것이 항상 올바르게 초기화되는 것은 아니라는 메시지를 본 것 같습니다. 시간 프레임이 준비되지 않은 경우에도 Init()이 종료될 수 있다고 연결된 것 같습니다

어제 나는 버그를 여러 번 보았습니다. MT5 아래의이 표시기가 TF로 전환되면 때로는 표시기 버퍼 가 비어 있지 않을 수 있습니다. 각 요소에 특정 값을 할당하지 않으면 이전 값이 유지되는 것 같습니다 OnCalculate()의 표시기 배열에서 ArrayInitialize를 Init() (arr, 0.0)에 삽입하려고 했습니다.

내가 올바르게 이해하는 한 :

- MT5에서 Init() 에서 초기화할 때 표시기 버퍼가 자동으로 초기화되지 않습니까? (MT4에서는 버퍼에 무언가가 남아 있었던 걸로 기억합니다.)

- Init() 의 MT5에서 히스토리가 로드되지 않은 경우 버퍼 배열의 크기를 알 수 없으므로 ArrayInitialize(arr, 0.0)도 버퍼를 항상 올바르게 초기화하지 않습니까?

 
Igor Makanu :

팬케이크! 바로 그거죠! 잘했어요!!! 예, 재미가 있는 곳입니다!

네... MT5에는 많은 차이점이 있습니다. 너무 많은 검사와 모든 종류의 예측이 프로그래머의 머리에 떠오릅니다...

예, 여기에 또 다른 질문이 있습니다. 얼마 전에 MT5에서 Init()의 모든 것이 항상 올바르게 초기화되는 것은 아니라는 메시지를 본 것 같습니다. 시간 프레임이 준비되지 않은 경우에도 Init()이 종료될 수 있다고 연결된 것 같습니다

어제 나는 버그를 여러 번 보았습니다. MT5 아래의이 표시기가 TF로 전환되면 때로는 표시기 버퍼 가 비어 있지 않을 수 있습니다. 각 요소에 특정 값을 할당하지 않으면 이전 값이 유지되는 것 같습니다 OnCalculate()의 표시기 배열에서 ArrayInitialize를 Init() (arr, 0.0)에 삽입하려고 했습니다.

내가 올바르게 이해하는 한 :

- MT5에서 Init() 에서 초기화할 때 표시기 버퍼가 자동으로 초기화되지 않습니까? (MT4에서는 버퍼에 무언가가 남아 있었던 걸로 기억합니다.)

- Init() 의 MT5에서 히스토리가 로드되지 않은 경우 버퍼 배열의 크기를 알 수 없으므로 ArrayInitialize(arr, 0.0)도 버퍼를 항상 올바르게 초기화하지 않습니까?

 //+------------------------------------------------------------------+
//|                                            PerfecTrend Lines.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                             https://mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link        "https://mql5.com/ru/users/artmedia70"
#property version    "1.00"
#property indicator_chart_window
#property indicator_buffers 9
#property indicator_plots    5
//--- plot Top
#property indicator_label1    "Top"
#property indicator_type1    DRAW_LINE
#property indicator_color1    clrRed
#property indicator_style1    STYLE_SOLID
#property indicator_width1    1
//--- plot Bottom
#property indicator_label2    "Bottom"
#property indicator_type2    DRAW_LINE
#property indicator_color2    clrBlue
#property indicator_style2    STYLE_SOLID
#property indicator_width2    1
//--- plot Candles
#property indicator_label3    "Open;High;Low;Close"
#property indicator_type3    DRAW_COLOR_CANDLES
#property indicator_color3    clrDodgerBlue , clrOrangeRed , clrDarkGray
#property indicator_style3    STYLE_SOLID
#property indicator_width3    1
//--- plot ArrowUP
#property indicator_label4    "ArrowUP"
#property indicator_type4    DRAW_ARROW
#property indicator_color4    clrRed
#property indicator_style4    STYLE_SOLID
#property indicator_width4    1
//--- plot ArrowDN
#property indicator_label5    "ArrowDN"
#property indicator_type5    DRAW_ARROW
#property indicator_color5    clrBlue
#property indicator_style5    STYLE_SOLID
#property indicator_width5    1
//--- input parameters
input uint      InpPeriodSlow     =   7 ;     // Slow length
input uint      InpDistanceSlow   =   0 ;     // Slow pip displace
input uint      InpPeriodFast     =   3 ;     // Fast length
input uint      InpDistanceFast   =   0 ;     // Fast pip displace
//--- indicator buffers
double          BufferTop[];
double          BufferBottom[];
double          BufferCandlesOpen[];
double          BufferCandlesHigh[];
double          BufferCandlesLow[];
double          BufferCandlesClose[];
double          BufferColors[];
double          BufferArrowUP[];
double          BufferArrowDN[];
//--- global variables
int             period_slow;
int             period_fast;
int             period_max;
double          distance_slow;
double          distance_fast;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- set global variables
   period_fast= int (InpPeriodFast< 1 ? 1 : InpPeriodFast);
   period_slow= int (InpPeriodSlow< 1 ? 1 : InpPeriodSlow);
   period_max= fmax (period_fast,period_slow);
   distance_fast=InpDistanceFast* Point ();
   distance_slow=InpDistanceSlow* Point ();
//--- indicator buffers mapping
   SetIndexBuffer ( 0 ,BufferTop, INDICATOR_DATA );
   SetIndexBuffer ( 1 ,BufferBottom, INDICATOR_DATA );
   SetIndexBuffer ( 2 ,BufferCandlesOpen, INDICATOR_DATA );
   SetIndexBuffer ( 3 ,BufferCandlesHigh, INDICATOR_DATA );
   SetIndexBuffer ( 4 ,BufferCandlesLow, INDICATOR_DATA );
   SetIndexBuffer ( 5 ,BufferCandlesClose, INDICATOR_DATA );
   SetIndexBuffer ( 6 ,BufferColors, INDICATOR_COLOR_INDEX );
   SetIndexBuffer ( 7 ,BufferArrowUP, INDICATOR_DATA );
   SetIndexBuffer ( 8 ,BufferArrowDN, INDICATOR_DATA );
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger ( 3 , PLOT_ARROW , 108 );
   PlotIndexSetInteger ( 4 , PLOT_ARROW , 108 );
//--- setting indicator parameters
   IndicatorSetString ( INDICATOR_SHORTNAME , "NeuroTrend" );
   IndicatorSetInteger ( INDICATOR_DIGITS , Digits ());
//--- setting buffer arrays as timeseries
   ArraySetAsSeries (BufferTop, true );
   ArraySetAsSeries (BufferBottom, true );
   ArraySetAsSeries (BufferCandlesOpen, true );
   ArraySetAsSeries (BufferCandlesHigh, true );
   ArraySetAsSeries (BufferCandlesLow, true );
   ArraySetAsSeries (BufferCandlesClose, true );
   ArraySetAsSeries (BufferColors, true );
   ArraySetAsSeries (BufferArrowUP, true );
   ArraySetAsSeries (BufferArrowDN, true );
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate ( const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[])
  {
//--- Установка массивов буферов как таймсерий
   ArraySetAsSeries (open, true );
   ArraySetAsSeries (high, true );
   ArraySetAsSeries (low, true );
   ArraySetAsSeries (close, true );
//--- Проверка и расчёт количества просчитываемых баров
   if (rates_total< fmax (period_max, 4 )) return 0 ;
   int limit=rates_total-prev_calculated;
   if (limit> 1 )
     {
      limit=rates_total-period_max- 1 ;
       ArrayInitialize (BufferTop, EMPTY_VALUE );
       ArrayInitialize (BufferBottom, EMPTY_VALUE );
       ArrayInitialize (BufferCandlesOpen, EMPTY_VALUE );
       ArrayInitialize (BufferCandlesHigh, EMPTY_VALUE );
       ArrayInitialize (BufferCandlesLow, EMPTY_VALUE );
       ArrayInitialize (BufferCandlesClose, EMPTY_VALUE );
       ArrayInitialize (BufferArrowUP, EMPTY_VALUE );
       ArrayInitialize (BufferArrowDN, EMPTY_VALUE );
     }
//---
   for ( int i=limit; i>= 0 && ! IsStopped (); i--)
     {
       int bhs= Highest (period_slow,i);
       int bls= Lowest (period_slow,i);
       int bhf= Highest (period_fast,i);
       int blf= Lowest (period_fast,i);
       if (bhs== WRONG_VALUE || bls== WRONG_VALUE || bhf== WRONG_VALUE || blf== WRONG_VALUE )
         continue ;
       double thigh1=high[bhs]+distance_slow;
       double tlow1=low[bls]-distance_slow;
       double thigh2=high[bhf]+distance_fast;
       double tlow2=low[blf]-distance_fast;
      
       double trendA=(close[i]>BufferTop[i+ 1 ] ? tlow1 : thigh1);
       double trendB=(close[i]>BufferBottom[i+ 1 ] ? tlow2 : thigh2);
      BufferTop[i]=trendA;
      BufferBottom[i]=trendB;

       double trendUP= 0 ;
       double trendDN= 0 ;
      
      BufferCandlesOpen[i]=open[i];
      BufferCandlesHigh[i]=high[i];
      BufferCandlesLow[i]=low[i];
      BufferCandlesClose[i]=close[i];
      BufferColors[i]= 2 ;
       if (close[i]<trendA && close[i]<trendB)
        {
         BufferColors[i]= 1 ;
         trendUP=high[i];
         trendDN=low[i];
        }
       else if (close[i]>trendA && close[i]>trendB)
        {
         BufferColors[i]= 0 ;
         trendUP=low[i];
         trendDN=high[i];
        }
       else
        {
         BufferCandlesOpen[i]= EMPTY_VALUE ;
         BufferCandlesHigh[i]= EMPTY_VALUE ;
         BufferCandlesLow[i]= EMPTY_VALUE ;
         BufferCandlesClose[i]= EMPTY_VALUE ;
        }
       static int trend= 0 ;
      BufferArrowUP[i]=BufferArrowDN[i]= EMPTY_VALUE ;
       if (close[i]>trendB && close[i]>trendA && trend!= 1 )
        {
         BufferArrowDN[i]=trendB;
         BufferArrowUP[i]= EMPTY_VALUE ;
         trend= 1 ;
        }
       if (close[i]<trendB && close[i]<trendA && trend!= 2 )
        {
         BufferArrowUP[i]=trendB;
         BufferArrowDN[i]= EMPTY_VALUE ;
         trend= 2 ;
        }
     }
   
//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+------------------------------------------------------------------+
//| Возвращает индекс максимального значения таймсерии High          |
//+------------------------------------------------------------------+
int Highest ( const int count, const int start, const bool as_series= true )
  {
   double array[];
   ArraySetAsSeries (array,as_series);
   return ( CopyHigh ( NULL , PERIOD_CURRENT ,start,count,array)==count ? ArrayMaximum (array)+start : WRONG_VALUE );
  }
//+------------------------------------------------------------------+
//| Возвращает индекс минимального значения таймсерии Low            |
//+------------------------------------------------------------------+
int Lowest ( const int count, const int start, const bool as_series= true )
  {
   double array[];
   ArraySetAsSeries (array,as_series);
   return ( CopyLow ( NULL , PERIOD_CURRENT ,start,count,array)==count ? ArrayMinimum (array)+start : WRONG_VALUE );
  }
//+------------------------------------------------------------------+

논리에는 별로 신경 쓰지 않았다.

 
Artyom Trishkin :

논리에는 별로 신경 쓰지 않았다.

따라서 더 정확할 것입니다. 최대/최소 가격에 대한 진입점을 설정할 것이 없습니다. 시작 가격이 더 좋습니다.

 //+------------------------------------------------------------------+
//|                                            PerfecTrend Lines.mq5 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                             https://mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link        "https://mql5.com/ru/users/artmedia70"
#property version    "1.00"
#property indicator_chart_window
#property indicator_buffers 9
#property indicator_plots    5
//--- plot Top
#property indicator_label1    "Top"
#property indicator_type1    DRAW_LINE
#property indicator_color1    clrRed
#property indicator_style1    STYLE_SOLID
#property indicator_width1    1
//--- plot Bottom
#property indicator_label2    "Bottom"
#property indicator_type2    DRAW_LINE
#property indicator_color2    clrBlue
#property indicator_style2    STYLE_SOLID
#property indicator_width2    1
//--- plot Candles
#property indicator_label3    "Open;High;Low;Close"
#property indicator_type3    DRAW_COLOR_CANDLES
#property indicator_color3    clrDodgerBlue , clrOrangeRed , clrDarkGray
#property indicator_style3    STYLE_SOLID
#property indicator_width3    1
//--- plot ArrowUP
#property indicator_label4    "ArrowUP"
#property indicator_type4    DRAW_ARROW
#property indicator_color4    clrRed
#property indicator_style4    STYLE_SOLID
#property indicator_width4    1
//--- plot ArrowDN
#property indicator_label5    "ArrowDN"
#property indicator_type5    DRAW_ARROW
#property indicator_color5    clrBlue
#property indicator_style5    STYLE_SOLID
#property indicator_width5    1
//--- input parameters
input uint      InpPeriodSlow     =   7 ;     // Slow length
input uint      InpDistanceSlow   =   0 ;     // Slow pip displace
input uint      InpPeriodFast     =   3 ;     // Fast length
input uint      InpDistanceFast   =   0 ;     // Fast pip displace
//--- indicator buffers
double          BufferTop[];
double          BufferBottom[];
double          BufferCandlesOpen[];
double          BufferCandlesHigh[];
double          BufferCandlesLow[];
double          BufferCandlesClose[];
double          BufferColors[];
double          BufferArrowUP[];
double          BufferArrowDN[];
//--- global variables
int             period_slow;
int             period_fast;
int             period_max;
double          distance_slow;
double          distance_fast;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- set global variables
   period_fast= int (InpPeriodFast< 1 ? 1 : InpPeriodFast);
   period_slow= int (InpPeriodSlow< 1 ? 1 : InpPeriodSlow);
   period_max= fmax (period_fast,period_slow);
   distance_fast=InpDistanceFast* Point ();
   distance_slow=InpDistanceSlow* Point ();
//--- indicator buffers mapping
   SetIndexBuffer ( 0 ,BufferTop, INDICATOR_DATA );
   SetIndexBuffer ( 1 ,BufferBottom, INDICATOR_DATA );
   SetIndexBuffer ( 2 ,BufferCandlesOpen, INDICATOR_DATA );
   SetIndexBuffer ( 3 ,BufferCandlesHigh, INDICATOR_DATA );
   SetIndexBuffer ( 4 ,BufferCandlesLow, INDICATOR_DATA );
   SetIndexBuffer ( 5 ,BufferCandlesClose, INDICATOR_DATA );
   SetIndexBuffer ( 6 ,BufferColors, INDICATOR_COLOR_INDEX );
   SetIndexBuffer ( 7 ,BufferArrowUP, INDICATOR_DATA );
   SetIndexBuffer ( 8 ,BufferArrowDN, INDICATOR_DATA );
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
   PlotIndexSetInteger ( 3 , PLOT_ARROW , 108 );
   PlotIndexSetInteger ( 4 , PLOT_ARROW , 108 );
//--- setting indicator parameters
   IndicatorSetString ( INDICATOR_SHORTNAME , "NeuroTrend" );
   IndicatorSetInteger ( INDICATOR_DIGITS , Digits ());
//--- setting buffer arrays as timeseries
   ArraySetAsSeries (BufferTop, true );
   ArraySetAsSeries (BufferBottom, true );
   ArraySetAsSeries (BufferCandlesOpen, true );
   ArraySetAsSeries (BufferCandlesHigh, true );
   ArraySetAsSeries (BufferCandlesLow, true );
   ArraySetAsSeries (BufferCandlesClose, true );
   ArraySetAsSeries (BufferColors, true );
   ArraySetAsSeries (BufferArrowUP, true );
   ArraySetAsSeries (BufferArrowDN, true );
//---
   return ( INIT_SUCCEEDED );
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate ( const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[])
  {
//--- Установка массивов буферов как таймсерий
   ArraySetAsSeries (open, true );
   ArraySetAsSeries (high, true );
   ArraySetAsSeries (low, true );
   ArraySetAsSeries (close, true );
//--- Проверка и расчёт количества просчитываемых баров
   if (rates_total< fmax (period_max, 4 )) return 0 ;
   int limit=rates_total-prev_calculated;
   if (limit> 1 )
     {
      limit=rates_total-period_max- 1 ;
       ArrayInitialize (BufferTop, EMPTY_VALUE );
       ArrayInitialize (BufferBottom, EMPTY_VALUE );
       ArrayInitialize (BufferCandlesOpen, EMPTY_VALUE );
       ArrayInitialize (BufferCandlesHigh, EMPTY_VALUE );
       ArrayInitialize (BufferCandlesLow, EMPTY_VALUE );
       ArrayInitialize (BufferCandlesClose, EMPTY_VALUE );
       ArrayInitialize (BufferArrowUP, EMPTY_VALUE );
       ArrayInitialize (BufferArrowDN, EMPTY_VALUE );
     }
//---
   for ( int i=limit; i>= 0 && ! IsStopped (); i--)
     {
       int bhs= Highest (period_slow,i);
       int bls= Lowest (period_slow,i);
       int bhf= Highest (period_fast,i);
       int blf= Lowest (period_fast,i);
       if (bhs== WRONG_VALUE || bls== WRONG_VALUE || bhf== WRONG_VALUE || blf== WRONG_VALUE )
         continue ;
       double thigh1=high[bhs]+distance_slow;
       double tlow1=low[bls]-distance_slow;
       double thigh2=high[bhf]+distance_fast;
       double tlow2=low[blf]-distance_fast;
      
       double trendA=(close[i]>BufferTop[i+ 1 ] ? tlow1 : thigh1);
       double trendB=(close[i]>BufferBottom[i+ 1 ] ? tlow2 : thigh2);
      BufferTop[i]=trendA;
      BufferBottom[i]=trendB;
      
      BufferCandlesOpen[i]=open[i];
      BufferCandlesHigh[i]=high[i];
      BufferCandlesLow[i]=low[i];
      BufferCandlesClose[i]=close[i];
      BufferColors[i]= 2 ;
       if (close[i]<trendA && close[i]<trendB)
         BufferColors[i]= 1 ;
       else if (close[i]>trendA && close[i]>trendB)
         BufferColors[i]= 0 ;
       else
        {
         BufferCandlesOpen[i]= EMPTY_VALUE ;
         BufferCandlesHigh[i]= EMPTY_VALUE ;
         BufferCandlesLow[i]= EMPTY_VALUE ;
         BufferCandlesClose[i]= EMPTY_VALUE ;
        }
       static int trend= 0 ;
      BufferArrowUP[i]=BufferArrowDN[i]= EMPTY_VALUE ;
       if (close[i]>trendB && close[i]>trendA && trend!= 1 )
        {
         BufferArrowDN[i]=open[i];
         BufferArrowUP[i]= EMPTY_VALUE ;
         trend= 1 ;
        }
       if (close[i]<trendB && close[i]<trendA && trend!= 2 )
        {
         BufferArrowUP[i]=open[i];
         BufferArrowDN[i]= EMPTY_VALUE ;
         trend= 2 ;
        }
     }
   
//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+------------------------------------------------------------------+
//| Возвращает индекс максимального значения таймсерии High          |
//+------------------------------------------------------------------+
int Highest ( const int count, const int start, const bool as_series= true )
  {
   double array[];
   ArraySetAsSeries (array,as_series);
   return ( CopyHigh ( NULL , PERIOD_CURRENT ,start,count,array)==count ? ArrayMaximum (array)+start : WRONG_VALUE );
  }
//+------------------------------------------------------------------+
//| Возвращает индекс минимального значения таймсерии Low            |
//+------------------------------------------------------------------+
int Lowest ( const int count, const int start, const bool as_series= true )
  {
   double array[];
   ArraySetAsSeries (array,as_series);
   return ( CopyLow ( NULL , PERIOD_CURRENT ,start,count,array)==count ? ArrayMinimum (array)+start : WRONG_VALUE );
  }
//+------------------------------------------------------------------+

그리고 선을 제거해야 합니다. 왜 차트에 있습니까? 드래그만 중지한다면?

 

유형이 없는 선언

포함 파일을 컴파일하면 오류가 없습니다. 이 포함 파일이 포함된 기본 프로그램 파일을 컴파일하면 형식 오류가 없는 선언이 발생합니다. 포함 파일 protected CSomeClass *object에 선언된 개체는 표시되지 않습니다. 포함 파일에는 #include "SomeClass.mqh" 지시문이 포함되어 있습니다. 그리고 메인 파일 에는 포함된 파일 클래스의 객체 가 생성되고 그 중 하나의 메소드가 호출됩니다.
사유: