请观看如何免费下载自动交易
请在Facebook上找到我们!
加入我们粉丝页
有趣的脚本?
因此发布一个链接 -
让其他人评价
喜欢这个脚本? 在MetaTrader 5客户端尝试它
指标

BalanceOfPower_Histogram_Alert - MetaTrader 5脚本

显示:
1237
等级:
(14)
已发布:
2017.01.25 09:05
已更新:
2023.03.29 14:34

真实作者:

RoboFx

能量均衡(Balance of Power, BOP)指标是一个彩色柱形图,它显示了当前趋势的强度和方向,并且可以发送提醒,电子邮件以及向移动设备上发送推送通知。柱状图的颜色是根据输入参数中超买和超卖,以及柱状图的变化方向来设置的。

为了实现提醒,发送电子邮件信息和推送通知,指标的代码做了如下改变:

  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 &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(ColorArray[index1]!=ColorIndex && 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+=Spread[index];
          string sAsk=DoubleToString(Ask,_Digits);
          string sBid=DoubleToString(Bid,_Digits);
          string sPeriod=GetStringTimeframe(ChartPeriod());
          if(SoundON) Alert("买入信号 \n 卖家报价=",Ask,"\n 买家报价=",Bid,"\n currtime=",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(ColorArray[index1]!=ColorIndex && 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+=Spread[index];
          string sAsk=DoubleToString(Ask,_Digits);
          string sBid=DoubleToString(Bid,_Digits);
          string sPeriod=GetStringTimeframe(ChartPeriod());
          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));
    //----
      }
    
  3. 在OnCalculate()模块指标计算循环中加入了一些对 BuySignal() 和 SellSignal() 函数的调用
    //---     
       BuySignal("BalanceOfPower_Histogram_Alert",ColorIndBuffer,0,rates_total,prev_calculated,close,spread);
       SellSignal("BalanceOfPower_Histogram_Alert",ColorIndBuffer,7,rates_total,prev_calculated,close,spread);
    //---
    

其中 ColorIndBuffer 是用于以索引形式保存烛形颜色的颜色索引缓冲区的名称,

在指标代码的 OnCalculate() 模块中,只会调用一个 BuySignal() 和 SellSignal() 函数。

本指标使用了 SmoothAlgorithms.mqh 开发库中的类 (把它复制到 <terminal_data_folder>\MQL5\Include 目录下),类的使用在文章"不使用额外的缓冲区来平均价格以用于中间计算"有完整描述。

本指标最初是使用MQL5语言开发并且首先于2013年2月7日发布于代码库中。

图1. 图表上的 BalanceOfPower_Histogram_Alert 指标

图1. 图表上的 BalanceOfPower_Histogram_Alert 指标

图2. 生成提醒的 BalanceOfPower_Histogram_Alert 指标。

图2. 生成提醒的 BalanceOfPower_Histogram_Alert 指标。

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

ColorJSatl_Digit_HTF ColorJSatl_Digit_HTF

在输入参数中带有时段选择选项的 ColorJSatl_Digit 指标。

si_q_asi_HTF si_q_asi_HTF

在输入参数中带有时段选择选项的 si_q_asi 指标。

ColorJFatl_Digit_Alert ColorJFatl_Digit_Alert

ColorJFatl_Digit 指标, 还有功能可以提醒,发送电子邮件以及向移动设备发送推送通知。

Exp_ColorJSatl_Digit Exp_ColorJSatl_Digit

Exp_ColorJSatl_Digit EA交易是基于 ColorJSatl_Digit 指标颜色变化的。