请观看如何免费下载自动交易
请在Twitter上找到我们!
加入我们粉丝页
有趣的脚本?
因此发布一个链接 -
让其他人评价
喜欢这个脚本? 在MetaTrader 5客户端尝试它
显示:
1802
等级:
(19)
已发布:
2017.02.07 12:04
已更新:
2023.03.29 14:34
需要基于此代码的EA交易或指标吗?请在自由职业者服务中订购 进入自由职业者服务

趋势指标 WeightOscillator, 拥有警报, 发送邮件和推送通知到移动设备的功能。

指标代码进行了以下修改, 以便实现报警, 邮件消息和推送通知:

  1. 在声明输入变量之前, 在全局范围声明指标信号生成选项的枚举。
    //+----------------------------------------------------+
    //| 用于信号生成选项的枚举                                   |
    //+----------------------------------------------------+
    enum ENUM_SIGNAL_MODE
      {
       MODE_SIGNAL,  //突破信号
       MODE_TREND    //突破和趋势信号
      };
  2. 介绍新的输入参数
    //---- 用于警报的输入变量
    input ENUM_SIGNAL_MODE SignMode=MODE_SIGNAL; //信号生成模式
    input uint NumberofBar=1;                    //生成信号的柱线数量
    input bool SoundON=true;                     //启用警报
    input uint NumberofAlerts=2;                 //警报次数
    input bool EMailON=false;                    //启用发送信号邮件
    input bool PushON=false;                     //启用发送信号到移动设备
  3. 在指标代码结尾处添加三个新函数: BuySignal(), SellSignal() 和 GetStringTimeframe()
    //+------------------------------------------------------------------+
    //| 买入信号函数                                                                            |
    //+------------------------------------------------------------------+
    void BuySignal(string SignalSirname,// 指标名称文本, 用于邮件和推送消息
                   double &ColorArray[],// 颜色索引缓存区
                   int ColorIndex,// 生成信号的颜色索引
                   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(ColorArray);
       int index,index1;
       if(SeriesTest)
         {
          index=int(NumberofBar);
          index1=index+1;
         }
       else
         {
          index=Rates_total-int(NumberofBar)-1;
          index1=index-1;
         }
       if(SignMode==MODE_SIGNAL)
         {
          if(ColorArray[index1]!=ColorIndex && ColorArray[index]==ColorIndex) BuySignal=true;
         }
       else
         {
          if(ColorArray[index]==ColorIndex) 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+=_Point*Spread[index];
          string sAsk=DoubleToString(Ask,_Digits);
          string sBid=DoubleToString(Bid,_Digits);
          string sPeriod=GetStringTimeframe(ChartPeriod());
          if(SignMode==MODE_SIGNAL || (SignMode==MODE_TREND && ColorArray[index1]!=ColorIndex))
            {
             if(SoundON) Alert("买入信号 \n 采购价=",采购价,"\n 供给价=",Bid,"\n 当前时间=",text,"\n 品种=",Symbol()," 周期=",sPeriod);
             if(EMailON) SendMail(SignalSirname+": 买入信号警报","买入信号采购价="+sAsk+", 供给价="+sBid+", 日期="+text+" 品种="+Symbol()+" 周期="+sPeriod);
             if(PushON) SendNotification(SignalSirname+": 买入信号采购价="+sAsk+", 供给价="+sBid+", 日期="+text+" 品种="+Symbol()+" 周期="+sPeriod);
            }
          else
            {
             if(SoundON) Alert("上行趋势信号 \n 采购价=",Ask,"\n 供给价=",Bid,"\n 当前时间=",text,"\n 品种=",Symbol()," 周期=",sPeriod);
             if(EMailON) SendMail(SignalSirname+": 上行趋势信号警报","买入信号采购价="+sAsk+", 供给价="+sBid+", 日期="+text+" 品种="+Symbol()+" 周期="+sPeriod);
             if(PushON) SendNotification(SignalSirname+": 上行趋势信号采购价="+sAsk+", 供给价="+sBid+", 日期="+text+" 品种="+Symbol()+" 周期="+sPeriod);
            }
         }

    //---
      }
    //+------------------------------------------------------------------+
    //| 卖出信号函数                                                                            |
    //+------------------------------------------------------------------+
    void SellSignal(string SignalSirname,// 邮件和推送消息的指标名文本
                    double &ColorArray[],       // 颜色索引缓存区
                    int ColorIndex,             // 生成信号的颜色索引
                    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(ColorArray);
       int index,index1;
       if(SeriesTest)
         {
          index=int(NumberofBar);
          index1=index+1;
         }
       else
         {
          index=Rates_total-int(NumberofBar)-1;
          index1=index-1;
         }

       if(SignMode==MODE_SIGNAL)
         {
          if(ColorArray[index1]!=ColorIndex && ColorArray[index]==ColorIndex) SellSignal=true;
         }
       else
         {
          if(ColorArray[index]==ColorIndex) 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+=_Point*Spread[index];
          string sAsk=DoubleToString(Ask,_Digits);
          string sBid=DoubleToString(Bid,_Digits);
          string sPeriod=GetStringTimeframe(ChartPeriod());
          if(SignMode==MODE_SIGNAL || (SignMode==MODE_TREND && ColorArray[index1]!=ColorIndex))
            {
             if(SoundON) Alert("卖出信号 \n 采购价=",Ask,"\n 供给价=",Bid,"\n 当前时间=",text,"\n 品种=",Symbol()," 周期=",sPeriod);
             if(EMailON) SendMail(SignalSirname+": 卖出信号警报","卖出信号采购价="+sAsk+", 供给价="+sBid+", 日期="+text+" 品种="+Symbol()+" 周期="+sPeriod);
             if(PushON) SendNotification(SignalSirname+": 卖出信号采购价="+sAsk+", 供给价="+sBid+", 日期="+text+" 品种="+Symbol()+" 周期="+sPeriod);
            }
          else
            {
             if(SoundON) Alert("下行趋势信号 \n 采购价=",Ask,"\n 供给价=",Bid,"\n 当前时间=",text,"\n 品种=",Symbol()," 周期=",sPeriod);
             if(EMailON) SendMail(SignalSirname+": 下行趋势信号警报","卖出信号采购价="+sAsk+", 供给价="+sBid+", 日期="+text+" 品种="+Symbol()+" 周期="+sPeriod);
             if(PushON) SendNotification(SignalSirname+": 下行趋势采购价="+sAsk+", 供给价="+sBid+", 日期="+text+" 品种="+Symbol()+" 周期="+sPeriod);
            }
         }
    //---
      }
    //+------------------------------------------------------------------+
    //| 获取时间帧的字符串 |
    //+------------------------------------------------------------------+
    string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
      {
    //----
       return(StringSubstr(EnumToString(timeframe),7,-1));
    //----
      }
  4. 在 OnCalculate() 模块的指标计算循环之后添加一对调用 BuySignal() 和 SellSignal() 函数。
    //---    
       BuySignal("WeightOscillator_Alert",ColorBuffer,0,rates_total,prev_calculated,close,spread);
       SellSignal("WeightOscillator_Alert",ColorBuffer,4,rates_total,prev_calculated,close,spread);
    //---  

其中 ColorBuffer 是用于存储指标颜色的颜色索引缓冲区的名称。值 0 和 4 是缓存器中的颜色数, 其中振荡器分别处于超买和超卖区域。 

假定在指标的 OnCalculate() 模块里仅调用一次 BuySignal() 和 SellSignal() 函数。

指标使用 SmoothAlgorithms.mqh 库类 (复制到 客户端数据文件夹\MQL5\Include)。类库的使用描述可参阅文章 "Averaging Price Series for Intermediate Calculations Without Using Additional Buffers(无需使用额外的缓冲区进行平均价格序列的中间计算)"

图例1. 图表上的 WeightOscillator_Alert 指标

图例1. 图表上的 WeightOscillator_Alert 指标

图例.3. WeightOscillator_Alert 指标。生成趋势信号报警

图例.2. WeightOscillator_Alert 指标。产生突破信号的报警

图例.3. WeightOscillator_Alert 指标。生成趋势信号报警

图例.3. WeightOscillator_Alert 指标。生成趋势信号报警

由MetaQuotes Ltd译自俄语
原代码: https://www.mql5.com/ru/code/17091

Fractional_Bands_HTF Fractional_Bands_HTF

指标 Fractional_Bands 在输入参数中有时间帧选项。

图表上的图表 图表上的图表

图表上的图表指标在当前图表上显示其它品种的图表。

Fractal_Keltner_x5_Cloud Fractal_Keltner_x5_Cloud

两个分形 Keltner 通道形成的云图。

eur usd m5 eur usd m5

智能交易系统依据 iStochastic (随机振荡器) 的信号遵照马丁格尔模式操作。