MQL5 CiBandsを使用した値の取得方法 インジケーターが表示されません。修正方法をご教示いただけますと幸いです。

 

MQL5初心者です。

以下のようにソースを作成しましたが、ボリンジャーバンドの線が表示されません。

問題点をご指摘頂けますでしょうか。


Print(BBs.Upper(pos_tmp));

で出力した値を見ると 「1.7976931348623157e+308」と表示されているため、個々が原因だと思うのですが、修正方法が分かりません。



//+------------------------------------------------------------------+
//|                                             stochastic-bb_01.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

//サブ画面にチャート表示する
#property indicator_chart_window //インディケーター表示箇所 indicator_chart_window:メインチャートに表示 indicator_separate_window:別チャートに表示

#property indicator_buffers 1 //表示するインディケータ用に必要な配列数
#property indicator_plots   1 //描画するインディケーターの数 

//ボリンジャーバンドMAIN
#property indicator_type1   DRAW_LINE
#property indicator_color1  Blue

//インディケーター用バッファ配列を宣言
double Buffer_BB_Main[];  

//---include
//オシレーターを使用するために標準ライブラリをインクルード
#include <Indicators/Trend.mqh> //CiBands クラスは、ボリンジャーバンド指標の作成、設定及びデータアクセスを提供します。

//---global
CiBands BBs;

//インプットパラメータ
input string               inp_symbol           = "USDJPY";          //通貨ペア
input ENUM_TIMEFRAMES      inp_timeframe        = PERIOD_CURRENT;    //時間軸
input int MA_span = 14; //移動平均用パラメタ

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
//初回起動時のみ呼ばれる関数
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0, Buffer_BB_Main, INDICATOR_DATA);
   PlotIndexSetInteger(0, PLOT_SHIFT, 0);
   PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 0);

   //パラメータを設定
               //シンボル  , 期間        ,平均期間,シフト,偏差値,適用された価格バンドル
   BBs.Create( inp_symbol, inp_timeframe, 14   ,0   , 2 ,PRICE_CLOSE);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,     //現在表示されているバーの本数
                const int prev_calculated, //計算処理済みのバーの本数
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   int start;
   int pos_tmp;
   double arr[];
    //表示済みのバーから、最新バーまでを計算
   for(int pos=prev_calculated;pos<=rates_total;pos++){
      if(pos>=MA_span){
         start = pos - MA_span;
        ArrayCopy(arr,close,0,start,MA_span);

        BBs.Refresh(); // 最新データに更新
        pos_tmp = pos -1;
        Buffer_BB_Main[pos_tmp] = BBs.Upper(pos_tmp);
        Print(pos_tmp);
        Print(BBs.Upper(1));
        Print(BBs.Upper(pos_tmp));
      }
   }
   
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
SetIndexBuffer(0, Buffer_BB_Main, INDICATOR_DATA);
ArraySetAsSeries(Buffer_BB_Main, true);
PlotIndexSetInteger(0, PLOT_SHIFT, 0);
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, MA_span);
for (int pos = rates_total; pos >= 0; pos--)
   {
      if(pos < rates_total - MA_span) //if(pos >= MA_span)
      {
         //start = pos - MA_span;
         //ArrayCopy(arr, close, 0, start, MA_span);

         BBs.Refresh(); // 最新データに更新
         //pos_tmp = pos - 1;
         //Buffer_BB_Main[pos_tmp] = BBs.Upper(pos_tmp);
         Buffer_BB_Main[pos] = BBs.Upper(pos);
         //Print(pos_tmp);
         //Print(BBs.Upper(1));
         //Print(BBs.Upper(pos_tmp));
      }
   }

 

Nagisa Unada #:


解決しました。ありがとうございます。

おかげさまで、ボリンジャーバンドが表示できました。

理由: