脚本: 月线 周线 级别

 

月线 周线 级别:

脚本在图表上显示月线和周线级别。

月线 周线 级别

作者: Taras Slobodyanik

 
脚本无法编译。它说 - 'iLow' - 模棱两可地调用具有相同参数的重载函数 mn1_w1_levels.mq5 113 19

 

新 MT5 默认支持这些功能,因此您可以直接从代码中删除它们。

已重新上传。

 
谢谢。成功了
 

您好

出于某种原因,将指标复制到指标文件夹后,它无法显示在 mt5 导航器中。

编译也无济于事。

有什么解决办法吗?

 
kehrman:

你好

出于某种原因,将指标复制到指标文件夹后,它无法显示在 mt5 导航器中。

编译也无济于事。

有解决方案吗?

你好、


我修改了这个脚本并进行了测试。对我有用。

附加的文件:
 

下载了脚本。

可能是作者没有重新上传 EA 代码或其他原因,27-03-2023 上的脚本无法运行。
编译后,出现了 14 条错误信息。

我阅读了前面的注释。
,我注释掉了三个代码块,作者在注释中说可以删除它们。

之后,在编译过程中出现了语法错误(第 220 行多了一个逗号)。
我删除了逗号并编译了代码。
所有错误都消失了,现在脚本可以在图表上运行了。

更正后的代码如下:

//+------------------------------------------------------------------+
//|MN1_W1_Levels.mq4
//|© Tecciztecatl ||
//+------------------------------------------------------------------+
#property copyright     "© Tecciztecatl 2016"
#property link          "113411@bk.ru"
#property version       "1.00"
#property description   "The script shows the highs and lows of weeks and months."
#property script_show_inputs
#property strict

input  int      days=200;                    //天数
extern string   comm0="";                    //- - - - ---- Weeks ---- - - - - - -
extern color    W1_Color=LimeGreen;          //W1 线条的颜色
input  int      W1_Width=3;                  //W1 行宽
extern ENUM_LINE_STYLE W1_style=STYLE_SOLID; //W1 行的样式 
extern string   comm1="";                    //- - - - ---- Months ---- - - - - -
extern color    MN1_Color=Orange;            //MN1 线条的颜色
input  int      MN1_Width=3;                 //MN1线宽
extern ENUM_LINE_STYLE MN1_style=STYLE_SOLID;//MN1 行的样式 

enum  choice0 {Trend_Line=0,Horizontal_Line=1};
input choice0 object=Trend_Line;             //趋势或水平线

datetime    ArrDate[1];
double      ArrDouble[1];
MqlDateTime time;
//+------------------------------------------------------------------+
//| 脚本程序启动功能|
//+------------------------------------------------------------------+
void OnStart()
  {
   DelObject();

   int weeks=(int)MathCeil(days/7)+1;
   if(weeks>Bars(_Symbol,PERIOD_W1)) weeks=Bars(_Symbol,PERIOD_W1)-1;
   if(weeks<0) {Alert("No historical data!"); return;}
   for(int i=weeks; i>=0; i--)
     {
      datetime w1=iTime(_Symbol,PERIOD_W1,i);
      TimeToStruct(w1,time);
      if(object==Trend_Line)
        {
         SetTrendLine("W1_High_"+(string)i+"_ln",
                      w1+86400,
                      iHigh(_Symbol,PERIOD_W1,i),
                      w1+7*86400,
                      W1_Color,
                      W1_Width,
                      W1_style,
                      0x0007ffff);
         SetTrendLine("W1_Low_"+(string)i+"_ln",
                      w1+86400,
                      iLow(_Symbol,PERIOD_W1,i),
                      w1+7*86400,
                      W1_Color,
                      W1_Width,
                      W1_style,
                      0x0007ffff);
        }
      else
        {
         SetHLine("W1_High_"+(string)i+"_ln",
                  iHigh(_Symbol,PERIOD_W1,i),
                  W1_Color,
                  W1_Width,
                  W1_style);
         SetHLine("W1_Low_"+(string)i+"_ln",
                  iLow(_Symbol,PERIOD_W1,i),
                  W1_Color,
                  W1_Width,
                  W1_style);
        }
     }

   TimeToStruct(TimeCurrent(),time);
   int month=(int)MathCeil((days-time.day)/30)+1;
   if(month>Bars(_Symbol,PERIOD_MN1)) month=Bars(_Symbol,PERIOD_MN1)-1;
   if(month<0) {Alert("No historical data!"); return;}
   for(int i=month; i>=0; i--)
     {

      datetime mn=iTime(_Symbol,PERIOD_MN1,i);
      TimeToStruct(mn,time);

      if(object==Trend_Line)
        {
         SetTrendLine("MN1_High_"+(string)i+"_ln",
                      mn,
                      iHigh(_Symbol,PERIOD_MN1,i),
                      mn+DayMonth(time.mon,mn)*86400,
                      MN1_Color,
                      MN1_Width,
                      MN1_style,
                      0x000fffff);
         SetTrendLine("MN1_Low_"+(string)i+"_ln",
                      mn,
                      iLow(_Symbol,PERIOD_MN1,i),
                      mn+DayMonth(time.mon,mn)*86400,
                      MN1_Color,
                      MN1_Width,
                      MN1_style,
                      0x000fffff);
        }
      else
        {
         SetHLine("MN1_High_"+(string)i+"_ln",
                  iHigh(_Symbol,PERIOD_MN1,i),
                  MN1_Color,
                  MN1_Width,
                  MN1_style);
         SetHLine("MN1_Low_"+(string)i+"_ln",
                  iLow(_Symbol,PERIOD_MN1,i),
                  MN1_Color,
                  MN1_Width,
                  MN1_style);
        }

     }

   ChartRedraw();
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
int DayMonth(int mon,datetime ttime)
  {
   int leap_year;
   TimeToStruct(ttime,time);
   switch(mon)
     {
      case  1:
      case  3:
      case  5:
      case  7:
      case  8:
      case 10:
      case 12:
         return(31);
      case  2:
         leap_year=time.year;
         if(time.year%100==0)
            leap_year/=100;
         return((leap_year%4==0)? 29 : 28);
      case  4:
      case  6:
      case  9:
      case 11:
         return(30);
     }
   return(0);
  }
//// 创建一行
void SetTrendLine(
                  const string         name,
                  datetime             time1,
                  double               price1,
                  datetime             time2,
                  color                cvet,
                  int                  widthL,
                  ENUM_LINE_STYLE      styleL,
                  int                  hide_TF
                  )
  {
   if(ObjectFind(0,name)<0) ObjectCreate(0,name,OBJ_TREND,0,time1,price1,time2,price1);
   ObjectMove(0,name,0,time1,price1);
   ObjectMove(0,name,1,time2,price1);
   ObjectSetInteger(0,name,OBJPROP_COLOR,cvet);
   ObjectSetInteger(0,name,OBJPROP_STYLE,styleL);
   ObjectSetInteger(0,name,OBJPROP_WIDTH,widthL);
   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
   ObjectSetInteger(0,name,OBJPROP_BACK,false);
   ObjectSetInteger(0,name,OBJPROP_ZORDER,1);
   ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);
   ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
   ObjectSetInteger(0,name,OBJPROP_TIMEFRAMES,hide_TF);
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
/*
datetime iTime(string symbol,ENUM_TIMEFRAMES timeframe,int index)
 {
 if(index<0) index=0;
 if(CopyTime(symbol,timeframe,index,1,ArrDate)>0) return(ArrDate[0]);
 else return(-1);
 }
 */
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
/*
double iLow(string symbol,ENUM_TIMEFRAMES timeframe,int index)
 {
 if(index < 0) return(-1);
 if(CopyLow(symbol,timeframe,index,1,ArrDouble)>0) return(ArrDouble[0]);
 else return(-1);
 }
 */
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
/*
double iHigh(string symbol,ENUM_TIMEFRAMES timeframe,int index)
 {
 if(index < 0) return(-1);
 if(CopyHigh(symbol,timeframe,index,1,ArrDouble)>0) return(ArrDouble[0]);
 else return(-1);
 }
 */
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void SetHLine(
              const string         name,
              double               price1,
              color                cvet,
              int                  widthL,
              ENUM_LINE_STYLE      styleL
              )
  {
   if(ObjectFind(0,name)<0) ObjectCreate(0,name,OBJ_HLINE,0,0,price1);
   ObjectSetDouble(0,name,OBJPROP_PRICE,price1);
   ObjectSetInteger(0,name,OBJPROP_COLOR,cvet);
   ObjectSetInteger(0,name,OBJPROP_STYLE,styleL);
   ObjectSetInteger(0,name,OBJPROP_WIDTH,widthL);
   ObjectSetInteger(0,name,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(0,name,OBJPROP_SELECTED,false);
   ObjectSetInteger(0,name,OBJPROP_BACK,false);
   ObjectSetInteger(0,name,OBJPROP_ZORDER,1);
   ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,false);
   ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void DelObject()
  {
   for(int i=ObjectsTotal(0,0,-1)-1;i>=0;i--)
     {
      string temp=ObjectName(0,i,0,-1);
      if(StringFind(temp,"_ln",0)>=0)
         ObjectDelete(0,temp);
     }
  }
//+------------------------------------------------------------------+
 
Alexandr #:

下载了脚本。

可能是作者没有重新上传 EA 代码或其他原因,27-03-2023 上的脚本无法运行。
在编译后,出现了 14 条错误信息。

Zip 压缩包没有更新,它包含的是第一个版本。
其他一切编译都没有错误(预览和 .mq5 文件)。

 
Taras Slobodyanik #:

Zip 压缩包未更新,它包含第一个版本。
其他所有编译都没有错误(预览和 .mq5 文件)。

我不知道通过代码审查可以获得更新。
所以我很惊讶在编译后看到这么多错误。
感谢您的解释。

 
此脚本也许只是系统中的一部分,1、里面的if条件恒为真,不存在else的情况,2、定义的数组后文没有体现。个人认为,单纯的划月线、周线的为了是什么呢,没感觉到有什么特别的用处,不过脚本里的函数调用、闰年的逻辑还是值得学习的。