指标: Reversal - 页 2

 
Christian:

繁殖和秩序在这里占了上风!:-)

......奶油般柔软,圣诞前的魅力......至少我是这么认为的

;)
 

我对这台 Indi 进行了重新编程。

从 286 条混乱的线精简到只有 151 条清晰的线,而且还可以做得更多。

现在,它是一个非常简单的指标,与 EMA 50(Steven Primo 的买入/卖出线)和合适的退出线等结合使用,具有很大的潜力。

//+------------------------------------------------------------------+
//|Reversal_V2.0.mq5
//| Copyright © 2019, Ing.版权所有
//| https://www.mql5.com/zh/users/kronenchakra |
//| https://www.mql5.com/zh/code/19605 |
//+------------------------------------------------------------------+
#property copyright     "版权所有 © 2019,奥托-保泽尔工程师"
#property link          "https://www.mql5.com/zh/users/kronenchakra"
#property version       "2.00"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2

//+------------------------------------------------------------------+
//| 输入参数|
//+------------------------------------------------------------------+
input int   inp_PeriodBack    =      10;  // 周期回溯
input int   inp_ArrowCodeDN   =     242;  // 出售箭头代码
input int   inp_ArrowCodeUP   =     241;  // 购买箭头代码
input color inp_ArrowColorDN  =  clrRed;  // 出售箭头颜色
input color inp_ArrowColorUP  = clrLime;  // 购买箭头颜色
input int   inp_ArrowSize     =       3;  // 箭头尺寸
input int   inp_ArrowOffs     =      30;  // 箭头偏移
input bool  inp_DrawRange     =    true;  // 绘制选中的范围
input bool  inp_SendMail      =   false;  // 根据信号发送邮件

//+------------------------------------------------------------------+
//| 指示器缓冲区|
//+------------------------------------------------------------------+
double buDN[];    // 缓冲箭头向下
double buUP[];    // 缓冲区箭头向上

//+------------------------------------------------------------------+
//| 自定义指示器初始化函数
//+------------------------------------------------------------------+
int OnInit()
{
   InitArrows(buDN,inp_ArrowCodeDN,inp_ArrowColorDN,inp_ArrowSize,-inp_ArrowOffs,"Sell");
   InitArrows(buUP,inp_ArrowCodeUP,inp_ArrowColorUP,inp_ArrowSize,+inp_ArrowOffs,"Buy" );
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| 自定义指标迭代函数
//+------------------------------------------------------------------+
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(high ,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(open ,true);
   ArraySetAsSeries(low  ,true);
   ArraySetAsSeries(time ,true);

   int limit=(prev_calculated==0)?0:rates_total-prev_calculated-1;

   for(int i=limit; i>=0; i--)
      {
         buDN[i]=NULL;
         buUP[i]=NULL;
         
         if(i>=MathMin(5000-1,rates_total-1-50)) continue; //使用一些旧的比率,以防止 "数组超出范围 "或计算速度过慢

                                                      //向下箭头
         if(high[1+i]==HH(high,inp_PeriodBack))       //蜡烛图高点等于阻力位
            if(close[1+i]<open[1+i])                  //烛台收盘价 < 烛台开盘价(看跌条形图)
               {
                  buDN[i]=high[i];                    //在烛台高点设置指标值
                  if(i==1) 
                     myAlert(time[1],"Sell");         //下一个酒吧开门时发出警报
               }
                                                      //向上箭头
         if(low[1+i]==LL(low,inp_PeriodBack))         //蜡烛图低点等于支撑点
            if(close[1+i]>open[1+i])                  //烛台收盘 > 烛台开盘(看涨条形图)
               {
                  buUP[i]=low[i];                     //在烛台低点设置指标值
                  if(i==1) 
                     myAlert(time[1],"Buy");          //下一个酒吧开门时发出警报
               }
      }

   if(inp_DrawRange)
      DrawRange("Range",time[inp_PeriodBack],HH(high,inp_PeriodBack),time[0],LL(low,inp_PeriodBack));

   return(rates_total);
}

//+------------------------------------------------------------------+
void myAlert(datetime aTime, string aMsg)    // 警报功能
{
   static datetime lastTime=NULL;
   if(aTime!=lastTime)
      {
         aMsg="Reversal_V2.9 @ "+_Symbol+","+PeriodShortStr(_Period)+" -> "+aMsg;
         Print(aMsg);
         if(inp_SendMail) 
            SendMail("Reversal_V2.9", aMsg);
         lastTime=aTime;
      }
}

string PeriodShortStr(ENUM_TIMEFRAMES _tf)            // 剪切前导 "PERIOD_"/返回 "M1"、"M10"、.... 
{
   return(StringSubstr(EnumToString(_tf),7));
}

//+------------------------------------------------------------------+
double HH(const double &aBuffer[], int aPeriBack)     // 一个时期的最高点向后退
{
   return(aBuffer[ArrayMaximum(aBuffer,0,aPeriBack)]);
}

double LL(const double &aBuffer[], int aPeriBack)     // 一个时期的最低点向后退
{
   return(aBuffer[ArrayMinimum(aBuffer,0,aPeriBack)]);
}

void DrawRange(string aName, datetime aBegin, double aHigh, datetime aEnd, double aLow)
{
   if(ObjectFind   (0,aName)==0) 
      ObjectDelete (0,aName);
   ObjectCreate    (0,aName,OBJ_RECTANGLE,0,aBegin,aHigh,aEnd,aLow);
   ObjectSetInteger(0,aName,OBJPROP_STYLE,STYLE_DASHDOT);
}
//+------------------------------------------------------------------+
//| 用箭头启动指示器缓冲区|
//+------------------------------------------------------------------+
void InitArrows(double &aBuffer[], int aArrowCode, color aArrowColor, int aArrowSize, int aArrowOffs, string aPlotLabel)
{
   static int idx=0;
   SetIndexBuffer(idx,aBuffer,INDICATOR_DATA);
   PlotIndexSetInteger(idx,PLOT_DRAW_TYPE  ,DRAW_ARROW);
   PlotIndexSetInteger(idx,PLOT_ARROW      ,aArrowCode);
   PlotIndexSetInteger(idx,PLOT_LINE_COLOR ,aArrowColor);
   PlotIndexSetInteger(idx,PLOT_LINE_WIDTH ,aArrowSize);
   PlotIndexSetInteger(idx,PLOT_ARROW_SHIFT,aArrowOffs);
   PlotIndexSetString (idx,PLOT_LABEL      ,aPlotLabel);
   PlotIndexSetDouble (idx,PLOT_EMPTY_VALUE,NULL);
   ArrayInitialize    (aBuffer,NULL);
   ArraySetAsSeries   (aBuffer,true);
   idx++;
}

这个指标很适合放在我的主页上,我的主页将于明年初上线。

附加的文件:
 
Otto Pauser:

我把这台 Indi 重新编程。

从 286 条混乱的线路精简到 151 条清晰的线路,而且可以做得更多。

现在,它是一个非常简单的指标,与 EMA 50(史蒂文-普里莫的买入/卖出线)和合适的退出线等配合使用,绝对具有潜力。

这个指标很适合放在我的主页上,我的主页将于明年初上线。

您真是太好了!我马上试用了一下,效果 非常好。非常感谢!

 
不工作
 
不工作
 
在元编辑器中编译时出现错误,请尽可能修复。感谢您免费提供如此有潜力的指标概念。
 
Joseph Kisakye #:
在元编辑器中编译时出现错误,请尽可能修复。

这是修改过的代码,没有错误。


//+------------------------------------------------------------------+
//|指标:reversal.mq5
//||
//||
//+------------------------------------------------------------------+
#property copyright "Sergey Vradiy"
#property version   "1.00"
#property description ""

//--- 指示器设置
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2

#property indicator_type1 DRAW_ARROW
#property indicator_width1 3
#property indicator_color1 0x0000FF
#property indicator_label1 "Sell"

#property indicator_type2 DRAW_ARROW
#property indicator_width2 3
#property indicator_color2 0xFFAA00
#property indicator_label2 "Buy"

//--- 指示器缓冲区
double Buffer1[];
double Buffer2[];

input int Interval=10;
datetime time_alert;     // 发送警报时使用
input bool Send_Email=true;
double myPoint; //在 OnInit 中初始化

//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void myAlert(string type,string message)
{
   if(type=="print")
      Print(message);
   else if(type=="error")
   {
      Print(type+" | reversal @ "+Symbol()+","+(string)Period()+" | "+message);
   }
   else if(type=="indicator")
   {
      if(Send_Email)
         SendMail("reversal",type+" | reversal @ "+Symbol()+","+(string)Period()+" | "+message);
   }
}
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void DrawLine(string objname,double price,int count,int start_index) //必要时创建或修改现有对象
{
   if((price<0) && ObjectFind(0,objname)>=0)
   {
      ObjectDelete(0,objname);
   }
   else if(ObjectFind(0,objname)>=0 && ObjectGetInteger(0,objname,OBJPROP_TYPE)==OBJ_TREND)
   {
      datetime Time[];
      ArraySetAsSeries(Time,true);
      CopyTime(Symbol(),Period(),0,start_index+count,Time);
      ObjectSetInteger(0,objname,OBJPROP_TIME,Time[start_index]);
      ObjectSetDouble(0,objname,OBJPROP_PRICE,price);
      ObjectSetInteger(0,objname,OBJPROP_TIME,1,Time[start_index+count-1]);
      ObjectSetDouble(0,objname,OBJPROP_PRICE,1,price);
   }
   else
   {
      datetime Time[];
      ArraySetAsSeries(Time,true);
      CopyTime(Symbol(),Period(),0,start_index+count,Time);
      ObjectCreate(0,objname,OBJ_TREND,0,Time[start_index],price,Time[start_index+count-1],price);
      ObjectSetInteger(0,objname,OBJPROP_RAY_LEFT,0);
      ObjectSetInteger(0,objname,OBJPROP_RAY_RIGHT,0);
      ObjectSetInteger(0,objname,OBJPROP_COLOR,C'0x00,0x00,0xFF');
      ObjectSetInteger(0,objname,OBJPROP_STYLE,STYLE_SOLID);
      ObjectSetInteger(0,objname,OBJPROP_WIDTH,2);
   }
}
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
double Support(int time_interval,bool fixed_tod,int hh,int mm,bool draw,int shift)
{
   int start_index=shift;
   int count=time_interval/PeriodSeconds();
   if(fixed_tod)
   {
      datetime start_time;
      datetime Time[];
      ArraySetAsSeries(Time,true);
      CopyTime(Symbol(),Period(),0,Bars(Symbol(),Period())-count,Time);
      if(shift==0)
         start_time=TimeCurrent();
      else
         start_time=Time[shift-1];
      datetime dt=StringToTime(TimeToString(start_time,TIME_DATE)+" "+(string)hh+":"+(string)mm); //最接近的时间 hh:mm
      if(dt>start_time)
         dt-=86400; //返回 24 小时
      int dt_index = iBarShift(Symbol(), Period(), dt, true);
      datetime dt2 = dt;
      while(dt_index<0 && dt>Time[Bars(Symbol(),Period())-1-count]) //bar not found => look a few days back
      {
         dt-=86400; //返回 24 小时
         dt_index=iBarShift(Symbol(),Period(),dt,true);
      }
      if(dt_index<0) //仍未找到 => 查找最近的酒吧
         dt_index =iBarShift(Symbol(), Period(), dt2, false);
      start_index=dt_index+1; //S/R在dt打开后的条形图
   }
   double _Low[];
   ArraySetAsSeries(_Low,true);
   CopyLow(Symbol(),Period(),start_index,count,_Low);
   double ret=_Low[ArrayMinimum(_Low,0,count)];
   if(draw) DrawLine("Support",ret,count,start_index);
   return(ret);
}
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
double Resistance(int time_interval,bool fixed_tod,int hh,int mm,bool draw,int shift)
{
   int start_index=shift;
   int count=time_interval/PeriodSeconds();
   if(fixed_tod)
   {
      datetime start_time;
      datetime Time[];
      ArraySetAsSeries(Time,true);
      CopyTime(Symbol(),Period(),0,Bars(Symbol(),Period())-count,Time);
      if(shift==0)
         start_time=TimeCurrent();
      else
         start_time=Time[shift-1];
      datetime dt=StringToTime(TimeToString(start_time,TIME_DATE)+" "+(string)hh+":"+(string)mm); //最接近的时间 hh:mm
      if(dt>start_time)
         dt-=86400; //返回 24 小时
      int dt_index = iBarShift(Symbol(), Period(), dt, true);
      datetime dt2 = dt;
      while(dt_index<0 && dt>Time[Bars(Symbol(),Period())-1-count]) //bar not found => look a few days back
      {
         dt-=86400; //返回 24 小时
         dt_index=iBarShift(Symbol(),Period(),dt,true);
      }
      if(dt_index<0) //仍未找到 => 查找最近的酒吧
         dt_index =iBarShift(Symbol(), Period(), dt2, false);
      start_index=dt_index+1; //S/R在dt打开后的条形图
   }
   double _High[];
   ArraySetAsSeries(_High,true);
   CopyHigh(Symbol(),Period(),start_index,count,_High);
   double ret=_High[ArrayMaximum(_High,0,count)];
   if(draw) DrawLine("Resistance",ret,count,start_index);
   return(ret);
}
//+------------------------------------------------------------------+
//| 自定义指示器初始化函数
//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0,Buffer1);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
   PlotIndexSetInteger(0,PLOT_ARROW,242);
   SetIndexBuffer(1,Buffer2);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);
   PlotIndexSetInteger(1,PLOT_ARROW,241);

   //初始化我的点
   myPoint=Point();
   if(Digits()==5 || Digits()==3)
   {
      myPoint*=10;
   }
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 自定义指标迭代函数|
//+------------------------------------------------------------------+
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 limit=rates_total-prev_calculated;
   if(limit<=0) return(rates_total);

//--- 从 0 开始计数到 rates_total
   ArraySetAsSeries(Buffer1,true);
   ArraySetAsSeries(Buffer2,true);

   //--- 初始零点
   if(prev_calculated<1)
   {
      ArrayInitialize(Buffer1,0);
      ArrayInitialize(Buffer2,0);
   }
   else
      limit++;

   //--- 主循环
   for(int i=limit-1; i>=0; i--)
   {
      if(i>=MathMin(5000-1,rates_total-1-50)) continue; //取消旧费率

      //指示器缓冲区 1(卖出)
      if(high[i]==Resistance(Interval*PeriodSeconds(),false,00,00,false,i)
         && close[i]<open[i]) //销售条件
      {
         Buffer1[i]=high[i]; //在烛台高点设置指标值
         if(i==1 && time[1]!=time_alert)
            myAlert("indicator","Sell"); //下一个酒吧开门时发出警报
         time_alert=time[1];
      }
      else
      {
         Buffer1[i]=0;
      }

      //指示器缓冲区 2(买入)
      if(low[i]==Support(Interval*PeriodSeconds(),false,00,00,false,i)
         && close[i]>open[i]) //购买条件
      {
         Buffer2[i]=low[i]; //在烛台低点设置指标值
         if(i==1 && time[1]!=time_alert)
            myAlert("indicator","Buy"); //下一个酒吧开门时发出警报
         time_alert=time[1];
      }
      else
      {
         Buffer2[i]=0;
      }
   }
   return(rates_total);
}
//+------------------------------------------------------------------+



 
bitcoin razak #:

这是修改后的代码,不会出错。




谢谢你,拉扎克,更新后的代码已成功编译。让我来测试一下,看看是否能像您在介绍中解释的那样运行。

我使用默认设置对该指标进行了回溯测试,但在图表上看不到任何买入和卖出箭头。如果确认有此错误,请重新检查代码。谢谢