首页 技术指标 帖子

艾略特波动振荡器信号警报 - MetaTrader 5 指标解析

附件
16171.zip (22.2 KB, 下载 0次)

真实作者:

本指标是基于 艾略特波动振荡器 算法的信号指标,支持警报、电子邮件通知以及手机推送通知功能。

为了实现这些警报功能,指标代码做了以下更改:

  1. 引入了新的输入参数:
    input uint NumberofBar=1;//信号的柱数
    input bool SoundON=true; //启用警报
    input uint NumberofAlerts=2;//警报数量
    input bool EMailON=false; //启用信号邮件
    input bool PushON=false; //启用手机推送信号
    
  2. 在指标代码末尾增加了三个新函数:BuySignal()、SellSignal() 和 GetStringTimeframe()
    //+------------------------------------------------------------------+
    //| 买入信号函数                                |
    //+------------------------------------------------------------------+
    void BuySignal(string SignalSirname,      // 用于邮件和推送消息的指标名称
                   double &BuyArrow[],        // 存储买入信号的指标缓冲区
                   const int Rates_total,     // 当前柱数
                   const int Prev_calculated, // 上一刻的柱数
                   const double &Close[],     // 收盘价
                   const int &Spread[])       // 点差
      {
    u//---
       static uint counter=0;
       if(Rates_total!=Prev_calculated) counter=0;
    
       bool BuySignal=false;
       bool SeriesTest=ArrayGetAsSeries(BuyArrow);
       int index;
       if(SeriesTest) index=int(NumberofBar);
       else index=Rates_total-int(NumberofBar)-1;
       if(NormalizeDouble(BuyArrow[index],_Digits) && BuyArrow[index]!=EMPTY_VALUE) BuySignal=true;
       if(BuySignal && counter<=NumberofAlerts)
         {
          counter++;
          MqlDateTime tm;
          TimeToStruct(TimeCurrent(),tm);
          string text=TimeToString(TimeCurrent(),TIME_DATE)+" "+string(tm.hour)+":"+string(tm.min);
          SeriesTest=ArrayGetAsSeries(Close);
          if(SeriesTest) index=int(NumberofBar);
          else index=Rates_total-int(NumberofBar)-1;
          double Ask=Close[index];
          double Bid=Close[index];
          SeriesTest=ArrayGetAsSeries(Spread);
          if(SeriesTest) index=int(NumberofBar);
          else index=Rates_total-int(NumberofBar)-1;
          Bid+=Spread[index];
          string sAsk=DoubleToString(Ask,_Digits);
          string sBid=DoubleToString(Bid,_Digits);
          string sPeriod=GetStringTimeframe(ChartPeriod());
          if(SoundON) Alert("BUY signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod);
          if(EMailON) SendMail(SignalSirname+": BUY signal alert","BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
          if(PushON) SendNotification(SignalSirname+": BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
         }
    
    u//---
      }
    //+------------------------------------------------------------------+
    //| 卖出信号函数                                             |
    //+------------------------------------------------------------------+
    void SellSignal(string SignalSirname,      // 用于邮件和推送消息的指标名称
                    double &SellArrow[],       // 存储卖出信号的指标缓冲区
                    const int Rates_total,     // 当前柱数
                    const int Prev_calculated, // 上一刻的柱数
                    const double &Close[],     // 收盘价
                    const int &Spread[])       // 点差
      {
    u//---
       static uint counter=0;
       if(Rates_total!=Prev_calculated) counter=0;
    
       bool SellSignal=false;
       bool SeriesTest=ArrayGetAsSeries(SellArrow);
       int index;
       if(SeriesTest) index=int(NumberofBar);
       else index=Rates_total-int(NumberofBar)-1;
       if(NormalizeDouble(SellArrow[index],_Digits) && SellArrow[index]!=EMPTY_VALUE) SellSignal=true;
       if(SellSignal && counter<=NumberofAlerts)
         {
          counter++;
          MqlDateTime tm;
          TimeToStruct(TimeCurrent(),tm);
          string text=TimeToString(TimeCurrent(),TIME_DATE)+" "+string(tm.hour)+":"+string(tm.min);
          SeriesTest=ArrayGetAsSeries(Close);
          if(SeriesTest) index=int(NumberofBar);
          else index=Rates_total-int(NumberofBar)-1;
          double Ask=Close[index];
          double Bid=Close[index];
          SeriesTest=ArrayGetAsSeries(Spread);
          if(SeriesTest) index=int(NumberofBar);
          else index=Rates_total-int(NumberofBar)-1;
          Bid+=Spread[index];
          string sAsk=DoubleToString(Ask,_Digits);
          string sBid=DoubleToString(Bid,_Digits);
          string sPeriod=GetStringTimeframe(ChartPeriod());
          if(SoundON) Alert("SELL signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod);
          if(EMailON) SendMail(SignalSirname+": SELL signal alert","SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
          if(PushON) SendNotification(SignalSirname+": SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
         }
    u//---
      }
    //+------------------------------------------------------------------+
    //| 获取时间框架字符串                                       |
    //+------------------------------------------------------------------+
    string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
      {
    //----
       return(StringSubstr(EnumToString(timeframe),7,-1));
    //----
      }
    
  3. 在指标计算周期的 OnCalculate() 块中,增加了对 BuySignal() 和 SellSignal() 函数的调用:
    u//---     
       BuySignal("Elliott_Wave_Oscillator_Sign",BuyBuffer,rates_total,prev_calculated,close,spread);
       SellSignal("Elliott_Wave_Oscillator_Sign",SellBuffer,rates_total,prev_calculated,close,spread);
    u//--- 
    

其中,BuyBuffer 和 SellBuffer 是存储买入和卖出信号的指标缓冲区。指标缓冲区中的空值可以设置为零或 EMPTY_VALUE。

假定在指标代码的 OnCalculate() 块中只使用一次 BuySignal() 和 SellSignal() 函数的调用。

原始指标已经包含生成警报的功能代码,但由于不必要而被移除。

该指标使用了 SmoothAlgorithms.mqh 库类(请将其复制到 <terminal_data_folder>\MQL5\Include)。该库类的使用在文章 "在不使用额外缓冲区的情况下对中间计算的价格序列进行平均" 中有详细描述。

该指标最初是用 MQL5 编写的,并于 2016 年 4 月 26 日首次发布在 代码库 中。

图1. 艾略特波动振荡器信号警报指标在图表上的表现

图1. 艾略特波动振荡器信号警报指标在图表上的表现

图2. 艾略特波动振荡器信号警报指标生成警报的过程

图2. 艾略特波动振荡器信号警报指标生成警报的过程

相关帖子

评论 (0)