#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 2
//--- 入力パラメータ
input int RSIperiod=14; // RSI を計算するための期間
input int Smooth=8; // 平滑化期間 RSI
input ENUM_MA_METHOD meth=MODE_SMMA; // 平滑化の方法
//---- RSI をプロットする
#property indicator_label1 "RSI"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//---- RSI_Smoothed をプロットする
#property indicator_label2 "RSI_Smoothed"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrNavy
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- 指標バッファ
double RSIBuffer[]; // RSI 値を収納
double RSI_SmoothedBuffer[]; // スムーズにされたRSI 値
int RSIhandle; // RSI 指標ハンドル
//+------------------------------------------------------------------+
//| カスタム指標を初期化する関数 |
//+------------------------------------------------------------------+
void OnInit()
{
//--- 指標バッファマッピング
SetIndexBuffer(0,RSIBuffer,INDICATOR_DATA);
SetIndexBuffer(1,RSI_SmoothedBuffer,INDICATOR_DATA);
IndicatorSetString(INDICATOR_SHORTNAME,"iRSI");
IndicatorSetInteger(INDICATOR_DIGITS,2);
//---
RSIhandle=iRSI(NULL,0,RSIperiod,PRICE_CLOSE);
//---
}
//+------------------------------------------------------------------+
//| カスタム指標の反復関数 |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const int begin,
const double &price[]
)
{
//--- 直近エラーの値をリセットする
ResetLastError();
//--- RSIBuffer[] 配列でRSIの指標データを取得する
int copied=CopyBuffer(RSIhandle,0,0,rates_total,RSIBuffer);
if(copied<=0)
{
Print("Unable to copy the values of the indicator RSI. Error = ",
GetLastError(),", copied =",copied);
return(0);
}
//--- RSI 値を用いて平均値の指標を作成する
int RSI_MA_handle=iMA(NULL,0,Smooth,0,meth,RSIhandle);
copied=CopyBuffer(RSI_MA_handle,0,0,rates_total,RSI_SmoothedBuffer);
if(copied<=0)
{
Print("Unable to copy the smoothed indicator of RSI. Error = ",
GetLastError(),", copied =",copied);
return(0);
}
//--- 次の呼び出しのために prev_calculated の値を返す
return(rates_total);
}
|