スポンサーリンク
検索

↑の検索エンジンが表示されない人は、
↓の古い検索エンジンを使用して下さい。
カスタム検索
MQL4リファレンスツリー
iMAOnArray


iMAOnArray


配列に格納した価格データを基にして移動平均インジケータを計算し、その値を返します。


関数書式:
double  iMAOnArray(
   double       array[],        // 配列データ
   int          total,          // 配列要素数
   int          ma_period,     // MAの平均期間
   int          ma_shift,      // MAシフト
   int          ma_method,     // MAの平均化メソッド
   int          shift          // シフト
   );



■引数
引数名 初期値 I/O 詳細
array[] - In 配列データ
total - In 配列要素数。
0指定は全要素を意味します。
ma_period - In メインラインを計算をする平均期間
ma_shift - In 移動平均シフト。
指定した時間軸のバー数でオフセットします
ma_method - In 移動平均メソッド。
ENUM_MA_METHOD列挙の値を指定します
shift - In インジケータバッファから取得する値のインデックス。
(現在バーを基準にして、指定した時間軸のバー数分を過去方向へシフト)


■戻り値
配列に格納した価格データを基にして計算した移動平均インジケータ計算値を返します



■備考
iMA()関数とは異なり、iMAOnArray()は通貨ペア名・時間軸・適用価格の引数はありません。
配列データ(価格データ)は事前に用意しておく必要があります。
インジケータは左から右へ計算します。
時系列配列(右から左)のような配列要素アクセスにするにはArraySetAsSeries()関数を使用する必要があります。

サンプルソース:
    double result = iMAOnArray(
                                  ExtBuffer,      // 配列データ
                                  0,              // 配列要素数
                                  14,             // MAの平均期間
                                  8,              // MAシフト
                                  MODE_SMMA,     // MAの平均化メソッド
                                  1               // シフト
                                 );


サンプルソース:
#property strict // strictは絶対に削除しない事
#property indicator_separate_window // カスタムインジケータをサブウインドウに表示する

// インジケータプロパティ設定
#property  indicator_buffers    2               // カスタムインジケータのバッファ数
#property  indicator_color1     clrWhite      // インジケータ1の色
#property  indicator_width1     2               // インジケータ1の太さ

#property  indicator_color2     clrRed      // インジケータ2の色
#property  indicator_width2     1               // インジケータ2の太さ


#property  indicator_minimum    0               // サブウインドウスケール下限値設定
#property  indicator_maximum  100               // サブウインドウスケール上限値設定

// レベルライン設定
#property  indicator_level1     30           // レベルライン1
#property  indicator_level2     70           // レベルライン2

#property  indicator_levelcolor   clrGray    // レベルラインの色
#property  indicator_levelstyle STYLE_DOT    // レベルラインの種類
#property  indicator_levelwidth         1    // レベルラインの太さ


// インジケータ表示用動的配列
double     _IndBuffer1[];                          // インジケータ1表示用動的配列
double     _IndBuffer2[];                          // インジケータ2表示用動的配列

// インプットパラメータ
input int  _InputCalPeriod          = 14;               // RSI算出期間
input int  _InputRSIMACalPeriod     = 25;               // RSIのMA算出期間


//+------------------------------------------------------------------+
//| OnInit(初期化)イベント
//+------------------------------------------------------------------+
int OnInit()
{
    SetIndexBuffer( 0, _IndBuffer1 );     // インジケータ1表示用動的配列をインジケータ1にバインドする
    SetIndexBuffer( 1, _IndBuffer2 );     // インジケータ2表示用動的配列をインジケータ1にバインドする

    return( INIT_SUCCEEDED );      // 戻り値:初期化成功
}


//+------------------------------------------------------------------+
//| OnCalculate(tick受信)イベント
//| カスタムインジケータ専用のイベント関数
//+------------------------------------------------------------------+
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[],   // Tick出来高
                const long     &volume[],        // Real出来高
                const int      &spread[])        // スプレッド
{
    int end_index = Bars - prev_calculated;  // バー数取得(未計算分)

    // RSI算出
    for( int icount = 0 ; icount < end_index ; icount++ ) {
        double get_value = iRSI (           // RSI算出
                             Symbol(),      // 通貨ペア
                             Period(),      // 時間軸
                             _InputCalPeriod, // 算出期間
                             PRICE_CLOSE,   // 適用価格
                             icount          // シフト
                        );

        _IndBuffer1[icount] = get_value;       // インジケータ1に算出結果を設定
    }

    // RSIのMA算出
    for( int icount = 0 ; icount < end_index ; icount++ ) {
        double get_rsi_ma = iMAOnArray(
                                      _IndBuffer1,           // 配列データ[RSIの算出結果の配列]
                                      0,                     // 配列要素数[配列の全要素対象]
                                      _InputRSIMACalPeriod,  // MAの平均期間
                                      0,                     // MAシフト
                                      MODE_SMA,            // MAの平均化メソッド
                                      icount                 // シフト
                                     );

        _IndBuffer2[icount] = get_rsi_ma;              // インジケータ2に算出結果を設定

    }

    return( rates_total ); // 戻り値設定:次回OnCalculate関数が呼ばれた時のprev_calculatedの値に渡される
}








スポンサーリンク
スポンサーリンク


Copyright ©2015 MT4でEA自作しちゃお~ All Rights Reserved.


Top

inserted by FC2 system