MQL4 및 MQL5에 대한 초보자 질문, 알고리즘 및 코드에 대한 도움말 및 토론 - 페이지 1292

 

안녕하세요.

저는 초보자입니다. 그러니 너무 저를 괴롭히지 마세요. )



https://www.mql5.com/en/articles/100

이 기사는 매수 신호가 있는 경우에만 매수 주문 을 해야 하고 오픈 롱 포지션이 없는 EA의 예를 제공합니다. 유사하게, 판매의 경우 - 판매 조건 및 오픈 숏 포지션의 부재.

첫 번째 테스트에서 한 위치가 아니라 여러 위치가 열린 것으로 나타났습니다. 질문 - 왜?


어드바이저 코드를 읽고 원인을 이해하고 찾으려고 노력했지만 모든 것이 괜찮은 것 같습니다.

Пошаговое руководство по написанию MQL5-советников для начинающих
Пошаговое руководство по написанию MQL5-советников для начинающих
  • www.mql5.com
Эта статья предназначена для начинающих, для тех, кто хочет научиться написанию простых советников на новом языке MQL5. Сначала мы определимся с тем, что требуется от нашего советника, а затем приступим к написанию того, каким образом он будет это делать. 1. Торговая стратегия Он будет следить за некоторыми индикаторами и при определенном...
파일:
 
Ivan Rodionov :

안녕하세요.

저는 초보자입니다. 그러니 너무 저를 괴롭히지 마세요. )

https://www.mql5.com/en/articles/100

이 기사는 매수 신호가 있는 경우에만 매수 주문 을 해야 하고 오픈 롱 포지션이 없는 EA의 예를 제공합니다. 유사하게, 판매의 경우 - 판매 조건 및 오픈 숏 포지션의 부재.

첫 번째 테스트에서 한 위치가 아니라 여러 위치가 열린 것으로 나타났습니다. 질문 - 왜?

어드바이저 코드를 읽고 원인을 이해하고 찾으려고 노력했지만 모든 것이 괜찮은 것 같습니다.

교체 시도

         if (Buy_opened)

         if (Buy_opened== true )

같은 판매

 
MakarFX :

교체 시도

같은 판매

도움이 되지 않습니다. 더 많은 문서를 읽어보세요.

 
안녕하세요! 나는 CODE를 사용하여 ZigZag의 무릎과 평행한 "추세선, 미래로"를 "드로잉"하는 방법을 알 수 없습니다. Expert Advisor에서 이 추세선을 넘는 가격 제어와 함께. 사실, 우리는 지그재그 오른쪽으로 이동합니다 . 알려주세요! 감사합니다!
 
Александр :
추세를 "그리다", 미래로"

직선 위의 두 점으로 미래를 포함하여 이 직선에서 임의의 세 번째 점의 가격을 찾을 수 있습니다(반대의 경우도 마찬가지).

 //находит дату точки (координату X) на прямой, на заданную цену (координата Y)
datetime GetPointTimeOnStraight( datetime eTime1, double ePrice1, datetime eTime2, double ePrice2, double ePrice3, string eSymbol, int eTimeFrame)
   {
   if (ePrice2-ePrice1== 0 ) return ( 0.0 );
   //индекс бара соответствующий заданному времени, возможно задавать будующее время
   int eIndex1=(eTime1> iTime (eSymbol,eTimeFrame, 0 ))?( int )(( iTime (eSymbol,eTimeFrame, 0 )-eTime1)/ PeriodSeconds (eTimeFrame)): iBarShift (eSymbol,eTimeFrame,eTime1);
   int eIndex2=(eTime2> iTime (eSymbol,eTimeFrame, 0 ))?( int )(( iTime (eSymbol,eTimeFrame, 0 )-eTime2)/ PeriodSeconds (eTimeFrame)): iBarShift (eSymbol,eTimeFrame,eTime2);
   int eIndex3=eIndex1+( int )((eIndex2-eIndex1)*(ePrice3-ePrice1)/(ePrice2-ePrice1));
   return ( iTime (eSymbol,eTimeFrame,eIndex3));
   }

//находит цену точки (координату Y) на прямой, на заданное время (координата X)
double GetPointPriceOnStraight( datetime eTime1, double ePrice1, datetime eTime2, double ePrice2, datetime eTime3, string eSymbol, int eTimeFrame)
   {
   //индекс бара соответствующий заданному времени, возможно задавать будующее время
   int eIndex1=(eTime1> iTime (eSymbol,eTimeFrame, 0 ))?( int )(( iTime (eSymbol,eTimeFrame, 0 )-eTime1)/ PeriodSeconds (eTimeFrame)): iBarShift (eSymbol,eTimeFrame,eTime1);
   int eIndex2=(eTime2> iTime (eSymbol,eTimeFrame, 0 ))?( int )(( iTime (eSymbol,eTimeFrame, 0 )-eTime2)/ PeriodSeconds (eTimeFrame)): iBarShift (eSymbol,eTimeFrame,eTime2);
   if (eIndex2-eIndex1== 0 ) return ( 0.0 );
   int eIndex3=(eTime3> iTime (eSymbol,eTimeFrame, 0 ))?( int )(( iTime (eSymbol,eTimeFrame, 0 )-eTime3)/ PeriodSeconds (eTimeFrame)): iBarShift (eSymbol,eTimeFrame,eTime3);
   return (ePrice1+(ePrice2-ePrice1)*(eIndex3-eIndex1)/(eIndex2-eIndex1));
   }
 
extern double Lot= 0.1 ;            
extern int Slippage = 3 ;
extern int TakeProfit = 30 ;
extern int StopLoss   = 30 ;
extern int MA_Smoth_S = 60 ;
extern int MA_Smoth_B = 12 ;
extern int MA_Simpl_S = 3 ;
extern int MA_Simpl_B = 1 ;
int start()
         {
           //___________________

           double SL, TP;
           int MA_Simpl_S_Cl,       //
              MA_Simpl_S_Op,       //
              MA_Simpl_B_Cl,       //
              MA_Simpl_B_Op;       //
         
           //________________

           //------------

          SL= NormalizeDouble (Bid-StopLoss* Point , Digits );       // 
          TP= NormalizeDouble (Bid+TakeProfit* Point , Digits );     //
          SL = StopLoss;                        
          TP = TakeProfit;
           if ( _Digits == 5 || _Digits == 3 )
            {
             SL = SL* 10 ;
             TP = TP* 10 ;
             return ( 0 );
            }
            
           //_______________

          MA_Smoth_S = iMA ( NULL , 0 , 60 , 0 , MODE_SMMA , PRICE_CLOSE , 1 );
          MA_Smoth_B = iMA ( NULL , 0 , 12 , 0 , MODE_SMMA , PRICE_CLOSE , 1 );
          MA_Simpl_S = iMA ( NULL , 0 , 3 , 0 , MODE_SMA , PRICE_CLOSE , 1 );
          MA_Simpl_B = iMA ( NULL , 0 , 1 , 0 , MODE_SMA , PRICE_CLOSE , 1 );
          MA_Simpl_S_Cl = iMA ( NULL , 0 , 3 , 0 , MODE_SMA , PRICE_CLOSE , 1 );
          MA_Simpl_S_Op = iMA ( NULL , 0 , 3 , 0 , MODE_SMA , PRICE_CLOSE , 2 );
          MA_Simpl_B_Cl = iMA ( NULL , 0 , 1 , 0 , MODE_SMA , PRICE_CLOSE , 1 );
          MA_Simpl_B_Op = iMA ( NULL , 0 , 1 , 0 , MODE_SMA , PRICE_CLOSE , 2 );
          
           //______________________

           while (MA_Smoth_B > MA_Smoth_S)
               {
                 if (MA_Simpl_B_Op < MA_Simpl_S_Op && MA_Simpl_B_Cl > MA_Simpl_S_Cl)
                  {
                   bool check = OrderSend ( Symbol (),OP_BUY,Lot, NormalizeDouble (Ask, Digits ),Slippage,SL,TP, "Buy" , 0 , 0 , clrGreen );
                   return ( 0 );
                  }
               }
               
           //_____________________

           while (MA_Smoth_S > MA_Smoth_B)
               {
                 if (MA_Simpl_B_Op > MA_Simpl_S_Op && MA_Simpl_B_Cl < MA_Simpl_S_Cl)
                  {
                   check = OrderSend ( Symbol (),OP_SELL,Lot, NormalizeDouble (Ask, Digits ),Slippage,SL,TP, "Sell" , 0 , 0 , clrRed );
                   return ( 0 );
                  }   
               }     
           return ( 0 );
         } 

안녕하세요.
" 체차코 "에 주목해주세요.
코드의 오류를 지적해야 하기 때문에 테스터에서 EA는 주문을 열지 않습니다 ...
동시에 컴파일러는 오류 및 경고를 발행하지 않으며 로그는 유사합니다. 오류가 없습니다 ...

 
Ivan Rodionov :

안녕하세요.

저는 초보자입니다. 그러니 너무 저를 괴롭히지 마세요. )

https://www.mql5.com/en/articles/100

이 기사는 매수 신호가 있는 경우에만 매수 주문 을 해야 하고 오픈 롱 포지션이 없는 EA의 예를 제공합니다. 유사하게, 판매의 경우 - 판매 조건 및 오픈 숏 포지션의 부재.

첫 번째 테스트에서 한 위치가 아니라 여러 위치가 열린 것으로 나타났습니다. 질문 - 왜?

어드바이저 코드를 읽고 원인을 이해하고 찾으려고 노력했지만 모든 것이 괜찮은 것 같습니다.

안녕 이반! 아무도 여기에 새로 온 사람들을 꾸짖지 않지만 반대로 그들은 도우려고 노력합니다. 나 자신은 초보자입니다. 이제 귀하의 질문에 대해. 포지션 개설에 대한 체크가 이루어졌기 때문에 여러 포지션이 개설되었지만 체크를 중지하는 것을 잊었습니다. return 문 은 호출 프로그램에 제어를 반환합니다(MQL5 참조에서 가져옴).

EA 코드에 반환 을 추가해야 합니다(노란색으로 강조 표시됨):

 //--- есть ли открытые позиции?
   bool Buy_opened= false ;   // переменные, в которых будет храниться информация 
   bool Sell_opened= false ; // о наличии соответствующих открытых позиций

   if ( PositionSelect ( _Symbol )== true ) // есть открытая позиция
     {
       if ( PositionGetInteger ( POSITION_TYPE )== POSITION_TYPE_BUY )
        {
         Buy_opened= true ;   //это длинная позиция
         return ;
        }
       else if ( PositionGetInteger ( POSITION_TYPE )== POSITION_TYPE_SELL )
        {
         Sell_opened= true ; // это короткая позиция
         return ;
        }
     }

또한 컴파일러가 경고를 발행하지 않도록 매수 및 매도 포지션을 여는 조건에서 OrderSend(mrequest,mresult) 를 확인하는 조건을 하나 더 추가해야 합니다. 이 조건은 if 문 에 의해 설정되며 다음과 같이 표시됩니다.

 //--- отсылаем ордер
if ( OrderSend (mrequest,mresult))

그리고 한 가지 더 고려해야 할 사항이 있습니다. 23:59:59에 한 거래일에서 다른 거래일로 전환하면 이전에 열린 포지션이 닫히고 00:00:00에 새 포지션이 즉시 열립니다. 이것은 특정 외환 딜러와 그의 거래 조건에 따라 달라지는 이른바 롤오버 마감 및 롤오버 오픈입니다. 포럼에서 검색하면 어딘가에 관련 정보가 있습니다.

안부 인사를 전합니다. 블라디미르.


 

안녕하세요. 사람들은 당신의 도움이 필요합니다. 매개변수가 다른 두 개의 지그재그를 하나의 표시기에 연결했습니다(오류 또는 경고 없음). 문제는 두 번째 지그재그가 잘못 그려지는 것입니다.

다음은 코드 자체입니다(MQL5).

 //+------------------------------------------------------------------+
//|                                                            6.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009-2017, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property version    "1.00"
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_plots    2
//---- plot ZigZag 1
#property indicator_label1    "ZigZag1"
#property indicator_type1    DRAW_SECTION
#property indicator_color1    clrRed
#property indicator_style1    STYLE_SOLID
#property indicator_width1    1
//---- plot ZigZag 2
#property indicator_label3    "ZigZag2"
#property indicator_type3    DRAW_SECTION
#property indicator_color3    clrBlueViolet
#property indicator_style3    STYLE_SOLID
#property indicator_width3    1
//--- input parameters ZigZag 1
input int       InpDepth    = 26 ;
input int       InpDeviation= 12 ;
input int       InpBackstep = 9 ;
//--- input parameters ZigZag 2
input int       Inp_Depth    = 12 ;
input int       Inp_Deviation= 5 ;
input int       Inp_Backstep = 3 ;
//--- indicator buffers ZigZag 1
double          ZigZagBuffer[];       //
double          HighMapBuffer[];     //
double          LowMapBuffer[];       //
int             ExtRecalc= 3 ;         //
//--- indicator buffers ZigZag 2
double          ZigZag_Buffer[];       // main buffer
double          HighMap_Buffer[];     // ZigZag high extremes (peaks)
double          LowMap_Buffer[];       // ZigZag low extremes (bottoms)
int             Ext_Recalc= 3 ;         // number of last extremes for recalculation
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
//--- indicator buffers mapping
   SetIndexBuffer ( 0 ,ZigZagBuffer, INDICATOR_DATA );
   SetIndexBuffer ( 1 ,HighMapBuffer, INDICATOR_CALCULATIONS );
   SetIndexBuffer ( 2 ,LowMapBuffer, INDICATOR_CALCULATIONS );
//
   SetIndexBuffer ( 3 ,ZigZag_Buffer, INDICATOR_DATA );
   SetIndexBuffer ( 4 ,HighMap_Buffer, INDICATOR_CALCULATIONS );
   SetIndexBuffer ( 5 ,LowMap_Buffer, INDICATOR_CALCULATIONS );

//--- set short name and digits
   PlotIndexSetString ( 0 , PLOT_LABEL , "ZigZag(" +( string )InpDepth+ "," +( string )InpDeviation+ "," +( string )InpBackstep+ ")" );
   PlotIndexSetString ( 3 , PLOT_LABEL , "ZigZag(" +( string )Inp_Depth+ "," +( string )Inp_Deviation+ "," +( string )Inp_Backstep+ ")" );

   IndicatorSetInteger ( INDICATOR_DIGITS , _Digits );

//--- set an empty value
   PlotIndexSetDouble ( 0 , PLOT_EMPTY_VALUE , 0.0 );
   PlotIndexSetDouble ( 3 , PLOT_EMPTY_VALUE , 0.0 );

//---
   return ( 0 );
  }
//+------------------------------------------------------------------+
//|  Search for the index of the highest bar                         |
//+------------------------------------------------------------------+
int Highest( const double &array[], int depth, int start)
  {
//--- validation of the start index
   if (start< 0 )
     {
       Print ( "Invalid parameter in the function Highest, start =" ,start);
       return 0 ;
     }
   int size= ArraySize (array);
//--- reduce depth to the available data if needed
   if (start-depth< 0 )
      depth=start;
   double max=array[start];
//--- start searching
   int index=start;
   for ( int i=start; i>start-depth; i--)
     {
       if (array[i]>max)
        {
         index=i;
         max=array[i];
        }
     }
//--- return index of the highest bar
   return (index);
  }
//+------------------------------------------------------------------+
//|  Search for the index of the lowest bar                          |
//+------------------------------------------------------------------+
int Lowest( const double &array[], int depth, int start)
  {
//--- validation of the start index
   if (start< 0 )
     {
       Print ( "Invalid parameter in the function iLowest, start =" ,start);
       return 0 ;
     }
   int size= ArraySize (array);
//--- reduce depth to the available data if needed
   if (start-depth< 0 )
      depth=start;
   double min=array[start];
//--- start searching
   int index=start;
   for ( int i=start; i>start-depth; i--)
     {
       if (array[i]<min)
        {
         index=i;
         min=array[i];
        }
     }
//--- return index of the lowest bar
   return (index);
  }
//--- auxiliary enumeration
enum EnSearchMode
  {
   Peak= 1 ,     // searching for the next ZigZag peak
   Bottom=- 1    // searching for the next ZigZag bottom
  };
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int zig( 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= 0 ;
   int limit= 0 ,extreme_counter= 0 ,extreme_search= 0 ;
   int shift= 0 ,back= 0 ,last_high_pos= 0 ,last_low_pos= 0 ;
   double val= 0 ,res= 0 ;
   double curlow= 0 ,curhigh= 0 ,last_high= 0 ,last_low= 0 ;
//--- initializing
   if (prev_calculated== 0 )
     {
       ArrayInitialize (ZigZag_Buffer, 0.0 );
       ArrayInitialize (HighMap_Buffer, 0.0 );
       ArrayInitialize (LowMap_Buffer, 0.0 );
     }
//---
   if (rates_total< 100 )
       //return(0);
       //--- set start position for calculations
       if (prev_calculated== 0 )
         limit=Inp_Depth;

//--- ZigZag was already calculated before
   if (prev_calculated> 0 )
     {
      i=rates_total- 1 ;
       //--- searching for the third extremum from the last uncompleted bar
       while (extreme_counter<ExtRecalc && i>rates_total- 100 )
        {
         res=ZigZag_Buffer[i];
         if (res!= 0 )
            extreme_counter++;
         i--;
        }
      i++;
      limit=i;

       //--- what type of exremum we search for
       if (LowMap_Buffer[i]!= 0 )
        {
         curlow=LowMap_Buffer[i];
         extreme_search=Peak;
        }
       else
        {
         curhigh=HighMap_Buffer[i];
         extreme_search=Bottom;
        }
       //--- clear indicator values
       for (i=limit+ 1 ; i<rates_total && ! IsStopped (); i++)
        {
         ZigZag_Buffer[i] = 0.0 ;
         LowMap_Buffer[i] = 0.0 ;
         HighMap_Buffer[i]= 0.0 ;
        }
     }

//--- searching for high and low extremes
   for (shift=limit; shift<rates_total && ! IsStopped (); shift++)
     {
       //--- low
      val=low[Lowest(low,Inp_Depth,shift)];
       if (val==last_low)
         val= 0.0 ;
       else
        {
         last_low=val;
         if ((low[shift]-val)>Inp_Deviation* _Point )
            val= 0.0 ;
         else
           {
             for (back= 1 ; back<=Inp_Backstep; back++)
              {
               res=LowMap_Buffer[shift-back];
               if ((res!= 0 ) && (res>val))
                  LowMap_Buffer[shift-back]= 0.0 ;
              }
           }
        }
       if (low[shift]==val)
         LowMap_Buffer[shift]=val;
       else
         LowMap_Buffer[shift]= 0.0 ;
       //--- high
      val=high[Highest(high,Inp_Depth,shift)];
       if (val==last_high)
         val= 0.0 ;
       else
        {
         last_high=val;
         if ((val-high[shift])>Inp_Deviation* _Point )
            val= 0.0 ;
         else
           {
             for (back= 1 ; back<=Inp_Backstep; back++)
              {
               res=HighMap_Buffer[shift-back];
               if ((res!= 0 ) && (res<val))
                  HighMap_Buffer[shift-back]= 0.0 ;
              }
           }
        }
       if (high[shift]==val)
         HighMap_Buffer[shift]=val;
       else
         HighMap_Buffer[shift]= 0.0 ;
     }

//--- set last values
   if (extreme_search== 0 ) // undefined values
     {
      last_low= 0 ;
      last_high= 0 ;
     }
   else
     {
      last_low=curlow;
      last_high=curhigh;
     }

//--- final selection of extreme points for ZigZag
   for (shift=limit; shift<rates_total && ! IsStopped (); shift++)
     {
      res= 0.0 ;
       switch (extreme_search)
        {
         case 0 : // search for an extremum
             if (last_low== 0 && last_high== 0 )
              {
               if (HighMap_Buffer[shift]!= 0 )
                 {
                  last_high=high[shift];
                  last_high_pos=shift;
                  extreme_search=Bottom;
                  ZigZag_Buffer[shift]=last_high;
                  res= 1 ;
                 }
               if (LowMap_Buffer[shift]!= 0 )
                 {
                  last_low=low[shift];
                  last_low_pos=shift;
                  extreme_search=Peak;
                  ZigZag_Buffer[shift]=last_low;
                  res= 1 ;
                 }
              }
             break ;
         case Peak: // search for peak
             if (LowMap_Buffer[shift]!= 0.0 && LowMap_Buffer[shift]<last_low && HighMap_Buffer[shift]== 0.0 )
              {
               ZigZag_Buffer[last_low_pos]= 0.0 ;
               last_low_pos=shift;
               last_low=LowMap_Buffer[shift];
               ZigZag_Buffer[shift]=last_low;
               res= 1 ;
              }
             if (HighMap_Buffer[shift]!= 0.0 && LowMap_Buffer[shift]== 0.0 )
              {
               last_high=HighMap_Buffer[shift];
               last_high_pos=shift;
               ZigZag_Buffer[shift]=last_high;
               extreme_search=Bottom;
               res= 1 ;
              }
             break ;
         case Bottom: // search for bottom
             if (HighMap_Buffer[shift]!= 0.0 && HighMap_Buffer[shift]>last_high && LowMap_Buffer[shift]== 0.0 )
              {
               ZigZag_Buffer[last_high_pos]= 0.0 ;
               last_high_pos=shift;
               last_high=HighMap_Buffer[shift];
               ZigZag_Buffer[shift]=last_high;
              }
             if (LowMap_Buffer[shift]!= 0.0 && HighMap_Buffer[shift]== 0.0 )
              {
               last_low=LowMap_Buffer[shift];
               last_low_pos=shift;
               ZigZag_Buffer[shift]=last_low;
               extreme_search=Peak;
              }
             break ;
         default :
             return (rates_total);
        }
     }

//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+------------------------------------------------------------------+
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= 0 ;
   int limit= 0 ,extreme_counter= 0 ,extreme_search= 0 ;
   int shift= 0 ,back= 0 ,last_high_pos= 0 ,last_low_pos= 0 ;
   double val= 0 ,res= 0 ;
   double curlow= 0 ,curhigh= 0 ,last_high= 0 ,last_low= 0 ;
//--- initializing
   if (prev_calculated== 0 )
     {
       ArrayInitialize (ZigZagBuffer, 0.0 );
       ArrayInitialize (HighMapBuffer, 0.0 );
       ArrayInitialize (LowMapBuffer, 0.0 );
     }
//---
   if (rates_total< 100 )
       return ( 0 );
//--- set start position for calculations
   if (prev_calculated== 0 )
      limit=InpDepth;

//--- ZigZag was already calculated before
   if (prev_calculated> 0 )
     {
      i=rates_total- 1 ;
       //--- searching for the third extremum from the last uncompleted bar
       while (extreme_counter<ExtRecalc && i>rates_total- 100 )
        {
         res=ZigZagBuffer[i];
         if (res!= 0 )
            extreme_counter++;
         i--;
        }
      i++;
      limit=i;

       //--- what type of exremum we search for
       if (LowMapBuffer[i]!= 0 )
        {
         curlow=LowMapBuffer[i];
         extreme_search=Peak;
        }
       else
        {
         curhigh=HighMapBuffer[i];
         extreme_search=Bottom;
        }
       //--- clear indicator values
       for (i=limit+ 1 ; i<rates_total && ! IsStopped (); i++)
        {
         ZigZagBuffer[i] = 0.0 ;
         LowMapBuffer[i] = 0.0 ;
         HighMapBuffer[i]= 0.0 ;
        }
     }

//--- searching for high and low extremes
   for (shift=limit; shift<rates_total && ! IsStopped (); shift++)
     {
       //--- low
      val=low[Lowest(low,InpDepth,shift)];
       if (val==last_low)
         val= 0.0 ;
       else
        {
         last_low=val;
         if ((low[shift]-val)>InpDeviation* _Point )
            val= 0.0 ;
         else
           {
             for (back= 1 ; back<=InpBackstep; back++)
              {
               res=LowMapBuffer[shift-back];
               if ((res!= 0 ) && (res>val))
                  LowMapBuffer[shift-back]= 0.0 ;
              }
           }
        }
       if (low[shift]==val)
         LowMapBuffer[shift]=val;
       else
         LowMapBuffer[shift]= 0.0 ;
       //--- high
      val=high[Highest(high,InpDepth,shift)];
       if (val==last_high)
         val= 0.0 ;
       else
        {
         last_high=val;
         if ((val-high[shift])>InpDeviation* _Point )
            val= 0.0 ;
         else
           {
             for (back= 1 ; back<=InpBackstep; back++)
              {
               res=HighMapBuffer[shift-back];
               if ((res!= 0 ) && (res<val))
                  HighMapBuffer[shift-back]= 0.0 ;
              }
           }
        }
       if (high[shift]==val)
         HighMapBuffer[shift]=val;
       else
         HighMapBuffer[shift]= 0.0 ;
     }

//--- set last values
   if (extreme_search== 0 ) // undefined values
     {
      last_low= 0 ;
      last_high= 0 ;
     }
   else
     {
      last_low=curlow;
      last_high=curhigh;
     }

//--- final selection of extreme points for ZigZag
   for (shift=limit; shift<rates_total && ! IsStopped (); shift++)
     {
      res= 0.0 ;
       switch (extreme_search)
        {
         case 0 : // search for an extremum
             if (last_low== 0 && last_high== 0 )
              {
               if (HighMapBuffer[shift]!= 0 )
                 {
                  last_high=high[shift];
                  last_high_pos=shift;
                  extreme_search=Bottom;
                  ZigZagBuffer[shift]=last_high;
                  res= 1 ;
                 }
               if (LowMapBuffer[shift]!= 0 )
                 {
                  last_low=low[shift];
                  last_low_pos=shift;
                  extreme_search=Peak;
                  ZigZagBuffer[shift]=last_low;
                  res= 1 ;
                 }
              }
             break ;
         case Peak: // search for peak
             if (LowMapBuffer[shift]!= 0.0 && LowMapBuffer[shift]<last_low && HighMapBuffer[shift]== 0.0 )
              {
               ZigZagBuffer[last_low_pos]= 0.0 ;
               last_low_pos=shift;
               last_low=LowMapBuffer[shift];
               ZigZagBuffer[shift]=last_low;
               res= 1 ;
              }
             if (HighMapBuffer[shift]!= 0.0 && LowMapBuffer[shift]== 0.0 )
              {
               last_high=HighMapBuffer[shift];
               last_high_pos=shift;
               ZigZagBuffer[shift]=last_high;
               extreme_search=Bottom;
               res= 1 ;
              }
             break ;
         case Bottom: // search for bottom
             if (HighMapBuffer[shift]!= 0.0 && HighMapBuffer[shift]>last_high && LowMapBuffer[shift]== 0.0 )
              {
               ZigZagBuffer[last_high_pos]= 0.0 ;
               last_high_pos=shift;
               last_high=HighMapBuffer[shift];
               ZigZagBuffer[shift]=last_high;
              }
             if (LowMapBuffer[shift]!= 0.0 && HighMapBuffer[shift]== 0.0 )
              {
               last_low=LowMapBuffer[shift];
               last_low_pos=shift;
               ZigZagBuffer[shift]=last_low;
               extreme_search=Peak;
              }
             break ;
         default :
             return (rates_total);
        }
     }

//--- return value of prev_calculated for next call
   return (rates_total);
  }
//+------------------------------------------------------------------+
 
Игорь :

안녕하세요. 사람들은 당신의 도움이 필요합니다. 매개변수가 다른 두 개의 지그재그를 하나의 표시기에 연결했습니다(오류 또는 경고 없음). 문제는 두 번째 지그재그가 잘못 그려지는 것입니다.

다음은 코드 자체입니다(MQL5).

모든 것이 당신을 위해 작동합니다 - 숫자 위에 약간 수정

파일:
h890d4.PNG  109 kb
6.mq5  17 kb
 
SanAlex :

모든 것이 당신을 위해 작동합니다 - 상단의 숫자를 약간 수정하십시오

도와 주셔서 감사합니다. 하나만 더 말해봐, 왜 하나의 지그재그는 평소와 같이 (최대, 최소) 형성되고 두 번째는 최대로만 형성되는지.