首页 技术指标 帖子

BykovTrendAlert - MetaTrader 5 的趋势信号指标

附件
16458.zip (3.75 KB, 下载 0次)

真实作者:

Ramdass - 仅进行转换

BykovTrend semaphore 信号指标为 MetaTrader 5 提供了警报功能,能够发送电子邮件和推送通知到移动设备。

为了实现警报、电子邮件和推送通知,指标代码进行了以下修改:

  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[])       // 点差
      {
    //---
       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("买入信号 
     Ask=",Ask,"
     Bid=",Bid,"
     当前时间=",text,"
     符号=",Symbol()," 周期=",sPeriod);
          if(EMailON) SendMail(SignalSirname+": 买入信号警报","买入信号在 Ask="+sAsk+", Bid="+sBid+", 日期="+text+" 符号="+Symbol()+" 周期="+sPeriod);
          if(PushON) SendNotification(SignalSirname+": 买入信号在 Ask="+sAsk+", Bid="+sBid+", 日期="+text+" 符号="+Symbol()+" 周期="+sPeriod);
         }
    
    //---
      }
    //+------------------------------------------------------------------+
    //| 卖出信号函数                                             |
    //+------------------------------------------------------------------+
    void SellSignal(string SignalSirname,      // 指标名称文本用于邮件和推送消息
                    double &SellArrow[],       // 存储卖出信号的指标缓冲区
                    const int Rates_total,     // 当前柱数
                    const int Prev_calculated, // 上一个刻度的柱数
                    const double &Close[],     // 收盘价格
                    const int &Spread[])       // 点差
      {
    //---
       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("卖出信号 
     Ask=",Ask,"
     Bid=",Bid,"
     当前时间=",text,"
     符号=",Symbol()," 周期=",sPeriod);
          if(EMailON) SendMail(SignalSirname+": 卖出信号警报","卖出信号在 Ask="+sAsk+", Bid="+sBid+", 日期="+text+" 符号="+Symbol()+" 周期="+sPeriod);
          if(PushON) SendNotification(SignalSirname+": 卖出信号在 Ask="+sAsk+", Bid="+sBid+", 日期="+text+" 符号="+Symbol()+" 周期="+sPeriod);
         }
    //---
      }
    //+------------------------------------------------------------------+
    //| 获取时间周期字符串                               |
    //+------------------------------------------------------------------+
    string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
      {
    //----
       return(StringSubstr(EnumToString(timeframe),7,-1));
    //----
      }
  3. 在 OnCalculate() 块的指标计算周期后添加了 BuySignal() 和 SellSignal() 函数的调用:
    //---     
       BuySignal("BykovTrendAlert",BuyBuffer,rates_total,prev_calculated,close,spread);
       SellSignal("BykovTrendAlert",SellBuffer,rates_total,prev_calculated,close,spread);
    //---
    

其中 BuyBuffer 和 SellBuffer 是存储买入和卖出信号的指标缓冲区。由于指示器缓冲区中的空值可以是零或 EMPTY_VALUE,必须进行设置。

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

此指标最初在 MQL4 中实现,并于 2007 年 9 月 28 日发布在 代码库

图1. BykovTrendAlert 指标在图表上的表现

图1. BykovTrendAlert 指标在图表上的表现


图2. BykovTrendAlert 指标生成警报

图2. BykovTrendAlert 指标生成警报。

相关帖子

评论 (0)