编码帮助 - 页 782

 
  1. 不要重复发帖!你已经打开了这个 主题。
    论坛的一般规则和最佳做法。- 一般 - MQL5编程论坛

  2. mcaesart: 但它并不像我想的那样工作。

    "不工作 "是没有意义的--就像说汽车不工作一样。不启动,不挂档,没有电,缺少钥匙,轮胎瘪了--毫无意义。
    如何以聪明的方式提出问题2004
    当问及代码时

 
mcaesart

我已经删除了你的相同主题的话题。

 
KristijanO: 我得到了很多错误......我得到的是意外标记错误。
  1. 不要为你的离题帖子劫持其他主题。你不是在寻求 "编码帮助"。下一次,请你自己做一个新的主题。

  2. 你真的希望得到答案吗?这里没有读心术,我们的水晶球也被破解了。我们无法看到你的破代码。你的一句话没有任何背景。你的问题很可能就在这上面。

  3. 发布所有相关的代码(比如那一行上面有什么。)
  4. 发布错误信息并指出哪一行有错误。

  5. 如何以聪明的方式提出问题2004
    修剪无意义的查询

 
auto_free_TEAMTRADER:

所有符号在我的平台上都可用。

在三个不同的平台上尝试了3个不同的renko指标,但仍然没有在renko图表上发挥作用。

所有其他指标都正常运行,它们是CCI、RSI和stochs。

还有人有什么建议吗?

TEAMTRADER

你好,Auto_free_Teamleader


我也有同样的问题,如果你已经找到了解决方案,请回复。

 
Rex Kalist:

你好,Auto_free_Teamleader


我也有同样的问题,如果你找到了解决方案,请回复。

auto_free_TEAMTRADER或Mladen ,请协助。
 

大家好,

我花了 3 周时间来创建一个自定义指标,但显然我不够好,希望有人能提供帮助。

我的指标采用 3 个外部参数:“时间范围”、“图表上显示级别的数量”和“每个级别之间的最小距离”。

我需要编码的只是分组,在最小距离内删除分形点,然后显示剩余的分形点级别。

我创建的第一个版本 (MainRS_AddOn2.mq4) 完全符合我的要求,但是我使用愚蠢的方法绘制对象并保持修改对象,指标运行速度极慢。

第二个版本(17_8_2020_RS_Indicator.mq4)将所有级别存储在缓冲区中,运行速度更快,但我遇到了无法修复的问题。

----我相信我在存储新的分形级别时存在逻辑错误,某些显示级别不符合最小距离要求,并且在测试仪中运行时获得了更多重复级别。

左侧是 17_8_2020_RS_Indicator.mq4,具有重复级别。

以上是测试仪内部的重复级别。


 if (modify == false ) // store new level when display level limit have no more room
                     {      
                                 if (RSMode[limit]== 1 )
                                    { 
                                       int index = ArrayMinimum (Display_level, WHOLE_ARRAY , 0 );
                                       Display_Mode[index]=RSMode[limit] ;
                                       Display_level[index]=RSBuffer1[limit];
                                    }  
                                 if (RSMode[limit]== 2 )
                                    { 
                                       int index = ArrayMaximum (Display_level, WHOLE_ARRAY , 0 );
                                       Display_Mode[index]=RSMode[limit] ;
                                       Display_level[index]=RSBuffer1[limit];
                                    }
                                    
                                  modify = true ; 
                                      
                     } 
                 }          

我认为上面的代码可能会导致逻辑错误。但除非他们愿意花时间查看整个文件,否则没有人能说出来。

感谢是否有人可以提供帮助。以下是完整代码,欢迎您复制粘贴或下载附件。

非常感谢。

 //+------------------------------------------------------------------+
//|                                             MainRS_Indicator.mq4 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link        "https://www.mql5.com"
#property version    "1.00"
#property description "Indicator to show Grouped Fractal Support and Resisitance Level"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#define Confirm_Level 3
#define Up_Fractal   1
#define Down_Fractal   2
#define Combined_Up   4
#define Combined_Down   5
 
enum timeframe_display_option
   {
    Current = 0 ,
    PeriodM5 = 5 ,
    PeriodM15 = 15 ,
    PeriodM30 = 30 ,
    PeriodH1 = 60 ,
    PeriodH4 = 240 ,
    PeriodD1 = 1440 ,
    PeriodW1 = 10080 ,
   };
double RSBuffer1[]; //hold new form fractal
double RSMode[]; //hold new form fractal status
double Display_level[]; // hold fractal display level 
double Display_Mode[]; // hold fractal display level status

extern int                        Show_Level_Limit = 15 ;         //Max Level to be display on chart
extern timeframe_display_option  Level_of_TimeFrame=Current; //Option to display which timeframe level on chart
extern double                     sensitvity = 15 ;     // Min distance between each RS level,input in pips values
int DisplayIndex = 0 ;


//++++ These are adjusted for 5 digit brokers.
   int      pips2points;     // slippage  3 pips    3=points    30=points
   double   pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
   int      Digitspips;     // DoubleToStr(dbl/pips2dbl, Digits.pips)
   string indId = "SR_" ;     // string to name object on chart for delete and create object
   double fractal;         // to store fractal point value
   bool modify = false ;     // to indicate a existing level on chart being modify or not
   double status; // status of display level, use to reduce and combine level within min distance
   color mark = clrRed ;                 

   //--------------------------------------------------
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit ()
  {
                                            
     if ( Digits % 2 == 1 )
     {       // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
                pips2dbl    = Point * 10 ; 
                pips2points = 10 ;   
                Digitspips = 1 ;
     } 
     else 
     {   pips2dbl    = Point ;    
         pips2points =   1 ;   
         Digitspips = 0 ; 
     }
   SetIndexBuffer ( 0 , RSBuffer1);
   SetIndexStyle( 0 , DRAW_ARROW );
   SetIndexArrow( 0 , 251 );   //buffer 0 draw line not symbol
   SetIndexEmptyValue( 0 , 0.0 );
   SetIndexBuffer ( 1 , RSMode);
   SetIndexStyle( 1 , DRAW_NONE );
   SetIndexArrow( 1 , 251 );   //buffer 0 draw line not symbol
   SetIndexEmptyValue( 1 , 0.0 );
   sensitvity = sensitvity * pips2dbl; // min distance of each display level/fractal point
     return ( 0 );

  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   DeleteAllObjects();
   return ( 0 );
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if (counted_bars > 0 )       //---- the last calculated bar will be recalculated   
      counted_bars--;
   int limit = Bars - counted_bars- 1 ;

//-------------------------------------------------------------------------------------------------  
//---- store fractal point to array   
//-------------------------------------------------------------------------------------------------  
   while (limit> 0 )
   { 
   fractal = iFractals ( NULL , Level_of_TimeFrame, MODE_UPPER, limit);
       if (fractal != 0 )
     {   
      RSBuffer1[limit]= fractal;
      RSMode[limit]= Up_Fractal;
     }
   fractal = iFractals ( NULL , Level_of_TimeFrame, MODE_LOWER, limit);
       if (fractal != 0 )
      {
      RSBuffer1[limit]= fractal;
      RSMode[limit]= Down_Fractal;
      }
//-----------------------------------------------------------------------------------------------------------------------------------------------      
//below status for fractal point reduction  
//Confirm_Level 3
//Up_Fractal  1
//Down_Fractal  2
//Combined_Up   4
//Combined_Down  5
//upper fractal point with another upper fractal point == combined up
//lower fractal point with another lower fractal point == combine down
//opposite fractal merge == confirm level (up & down || up & combine down || up && confirm || down & up || down & combine up ||down && confirm)
//--------------------------------------------------------------------------------------------------------------------------------------------------

   ArrayResize (Display_level,Show_Level_Limit+ 1 );
   ArrayResize (Display_Mode,Show_Level_Limit+ 1 );
     if ( RSBuffer1[limit]!= 0 )
     { 
       for ( int i=Show_Level_Limit- 1 ;  i>= 0 ; i--)
      {
         double diff = MathAbs (RSBuffer1[limit]-Display_level[i]); // calculate min distance between level
         modify = false ;

                   if (diff<=sensitvity ) //new fractal, check against Displaylevel
                     {  
                         if (Display_Mode[i]== 1 && RSMode[limit] == 1 ) // 
                           {   
                                 Display_Mode[i]= 4 ; // mode up & up = combine up
                                 if (RSBuffer1[limit]<Display_level[i])
                                    Display_level[i]=Display_level[i];
                                    
                               Comment (   " Up & Up== " + Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                           }
                         if (Display_Mode[i]== 4 && RSMode[limit] == 1 )
                           {
                                    Display_Mode[i]= 4 ; // mode combine up & up = combine up
                                     if (RSBuffer1[limit]<Display_level[i])
                                       Display_level[i]=Display_level[i];
                               Comment (   " Up & combine Up== " + Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                           }      
                         if (Display_Mode[i]== 2 && RSMode[limit] == 2 )
                           {  
                                  Display_Mode[i]= 5 ; // mode down & down = combine down
                                   if (RSBuffer1[limit]>Display_level[i])
                                    Display_level[i]=Display_level[i];
                               Comment (   "down & down== " + Display_level[i]+ "Display_Mode = " +Display_Mode[i]); 
                           }
                         if (Display_Mode[i]== 5 && RSMode[limit] == 2 )
                           {
                                    Display_Mode[i]= 5 ; // mode down & combine down  = combine down
                                     if (RSBuffer1[limit]>Display_level[i])
                                       Display_level[i]=Display_level[i];
                               Comment (   " Down & combine down== " + Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                           }   
                         
                     }    

                     if (diff<=sensitvity) 
                     {    
                         
                         if ((Display_Mode[i]== 2 && RSMode[limit] == 1 )||(Display_Mode[i]== 1 && RSMode[limit] == 2   ))
                           {
                               Display_Mode[i]= 3 ; // mode  up & down & combine down  = confirm 
                                    Display_level[i]=Display_level[i];
                               Comment (   "Up & down or combine down == " + Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                              modify = true ;
                               break ;
                           }                          
                         if ( (Display_Mode[i]== 3 || Display_Mode[i]== 5 ))
                           {
                               Display_Mode[i]= 3 ; // mode  up & confirm level = confirm 
                               Display_level[i]=Display_level[i];
                               Comment (   "Up & confirm level== " + Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                              modify = true ;
                               break ;
                           }
                           
                         if ( Display_Mode[i]== 3 || Display_Mode[i]== 4 )
                           {
                               Display_Mode[i]= 3 ; // mode  down & confirm level = confirm 
                               Display_level[i]=Display_level[i];
                               Comment (   "Down & confirm level== " + Display_level[i]+ "Display_Mode = " +Display_Mode[i]);
                              modify = true ;
                               break ;
                           }
                           
                     }
                  
       } //end of modify existing level for loop 
                  
                   if (modify == false ) // store disply level untill reacah show level limit
                  { 
                     for ( int a= 0 ;  a<Show_Level_Limit- 1 ; a++)
                     { 
                         if (Display_Mode[a]== 0 )
                        {
                           Display_Mode[a]=RSMode[limit];
                           Display_level[a] = RSBuffer1[limit];
                           
                           modify = true ;
                           break ;
                        } 
                        a++;  
                     }
                 
                   if (modify == false ) // store new level when display level limit have no more room
                     {      
                                 if (RSMode[limit]== 1 )
                                    { 
                                       int index = ArrayMinimum (Display_level, WHOLE_ARRAY , 0 );
                                       Display_Mode[index]=RSMode[limit] ;
                                       Display_level[index]=RSBuffer1[limit];
                                    }  
                                 if (RSMode[limit]== 2 )
                                    { 
                                       int index = ArrayMaximum (Display_level, WHOLE_ARRAY , 0 );
                                       Display_Mode[index]=RSMode[limit] ;
                                       Display_level[index]=RSBuffer1[limit];
                                    }
                                    
                                  modify = true ; 
                                      
                     } 
                 }          
      }

      limit--;
      
   }    
                  DeleteAllObjects();
                 
                   int uplevel= 1 ;
                   int downlevel= 1 ;
                   ArraySort (Display_level, WHOLE_ARRAY , 0 ,MODE_ASCEND);
                  DisplayIndex = 0 ;
                   for ( int a= 0 ;a< ArraySize (Display_level)- 1 ; a++)
                  {
                         if (Display_level[a]<Bid && Display_level[a+ 1 ]>Bid)
                           DisplayIndex =a+ 1 ;
                  }         

                     for ( int c =DisplayIndex ; c<=Show_Level_Limit; c++)
                  {         
                     HLine( "SR_RES" +uplevel+ " # " + c, Display_level[c],mark);
                     uplevel++;
                  }   
                     for ( int c =DisplayIndex- 1 ; c> 0 ; c--)
                  {         
                     HLine( "SR_SUP" +downlevel+ " # " + c, Display_level[c],mark);
                     downlevel++;
                  }   

                     

       



return ( 0 );
   } 
void HLine( string name, double P0, color clr)
      {
           #define WINDOW_MAIN 0
     /**/    if ( ObjectMove ( name, 0 , Time[ 0 ], P0 )){}
             else if (! ObjectCreate ( name, OBJ_HLINE , WINDOW_MAIN, Time[ 0 ], P0 ))
                     Alert ( "ObjectCreate(" ,name, ",HLINE) failed: " , GetLastError () );
           if (!ObjectSet(name, OBJPROP_COLOR , clr )) // Allow color change
                   Alert ( "ObjectSet(" , name, ",Color) [1] failed: " , GetLastError () );
           if (!ObjectSetText(name, PriceToStr(P0), 10 ))
                     Alert ( "ObjectSetText(" ,name, ") [1] failed: " , GetLastError ());
}
void DeleteAllObjects()
{
   // Delete all objects created by the indicator
   for ( int i = ObjectsTotal () - 1 ;  i >= 0 ;  i--)
   {
       string name = ObjectName (i);
      
       if ( StringSubstr (name, 0 , StringLen (indId)) == indId)
         ObjectDelete (name);
   }
}
 
string   PriceToStr( double p)
   {
     string pFrc = DoubleToStr(p, Digits );       
     if (Digitspips== 0 ) 
       return (pFrc);
     string pPip = DoubleToStr(p, Digits - 1 );
     if (pPip+ "0" == pFrc)       
       return (pPip);           
       return (pFrc);          
   }
//---------------------------------------------------------------------------------------------  
double Price( double Old, double New, int result) //1 return larger value, 2 return smaller value
   { 
   double value= 0 ;
   if (result== 1 )
   value= MathMax (Old,New);
   if (result== 2 )
   value= MathMin (Old,New);
   return (value);
   }
//---------------------------------------------------------------------------------------------   
附加的文件:
 

如果我劫持其他线程,我真的很抱歉

只是希望有人能帮助指出我在代码中的错误,以便我能够解决我的重复显示水平问题。

非常感谢

 
wccmcd:

我试图从MQL4转移到MQL5,但在第一步就卡住了。对于iCCI函数,为什么没有 "shift "参数了?

请编辑您的帖子,并在粘贴时

在粘贴代码时使用代码按钮(Alt+S)。

本节是MQL4。

MQL5,你在OnInit创建一个句柄,并在主代码中访问缓冲区的值。

我建议你阅读MQL5的文档

 
Keith Watford:

请编辑你的帖子并

粘贴代码时使用代码按钮(Alt+S)。

本节是MQL4。

MQL5,你在OnInit创建一个句柄,并在主代码中访问缓冲区的值。

我建议你阅读MQL5的文档

很抱歉。我刚刚意识到我发错了地方。 谢谢你的回复,通过。我刚刚删除了它。
 
你好。
我是一个学习mql4的初学者。我正在尝试创建一个基本的超级趋势指标。
我需要一些专家的帮助,关于警报代码。


目前的警报代码
Alert(Symbol() + " (" + Period() + "M) --> " + LSignal + CPri)。

输出结果是这样的
符号名称(15M)-->在524.55买入

但是,根据以下简单计算,我需要在警报中设置止损和目标。

假设我们在524.55买入。

止损: 进场-股票进场价的1.5%(524.55-7.85=516.70)。
目标1: 进场价+进场价的2.5% (524.55 + 13.10 = 537.65)
目标2: 进场+股票价格的5% (524.55 + 26.20 = 550.75)

(注意:Tick size是0.05。因此,如果止损或目标的计算是一个奇数,需要四舍五入到最近的tick大小。如果LSignal是一个卖出信号,需要反向计算。


最后我需要以下输出
符号名称(15M)-->在524.55买入,SL:516.70,目标1:537.65,目标2:550.75


谁能根据我的要求重写一下代码?

谢谢。