ホーム テクニカル指標 投稿

BalanceOfPower_Histogram_Alert - MetaTrader 5用のインジケーター

添付ファイル
16403.zip (22.71 KB, ダウンロード 0回)

著者: RoboFx

バランスオブパワー (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() を追加しました。
    //+------------------------------------------------------------------+
    //| Buy signal function                                              |
    //+------------------------------------------------------------------+
    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("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);
         }
    
    //---
      }
    //+------------------------------------------------------------------+
    //| Sell signal function                                               |
    //+------------------------------------------------------------------+
    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("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);
         }
    //---
      }
    //+------------------------------------------------------------------+
    //|  タイムフレームを文字列として取得する                               |
    //+------------------------------------------------------------------+
    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は、ローソク足の色をインデックス形式で保存するためのカラーインデックスバッファの名前です。

BuySignal()およびSellSignal()関数は、インジケーターコードのOnCalculate()ブロック内で1回のみ呼び出されることを想定しています。

このインジケーターは、SmoothAlgorithms.mqhライブラリのクラスを使用しています(<terminal_data_folder>\MQL5\Include にコピーしてください)。クラスの使用については、「追加バッファを使用せずに中間計算のための価格系列の平均化」の記事で詳しく説明されています。

このインジケーターは元々MQL5で作成され、2013年2月7日にCode Baseで初めて公開されました。

図1. BalanceOfPower_Histogram_Alertインジケーターのチャート

図1. BalanceOfPower_Histogram_Alertインジケーターのチャート

図2. BalanceOfPower_Histogram_Alertインジケーターがアラートを生成

図2. BalanceOfPower_Histogram_Alertインジケーターがアラートを生成

関連記事

コメント (0)