【解説】【MQL5 community】 Price Rate of Change (プライス・レート・オブ・チェンジ): 現在の価格とn期前の価格との変化率を表す。 変動幅が大きければ大きいほど、修正が入る確立は高まり、 逆に変動幅が小さいときはトレンドが出ていないと判断します。 またモメンタムとほぼ同じ動き方をします。
【計算法】
i期のROC
ROC = {(i期の終値 - (i-n)期の終値) / (i-n)期の終値} * 100
【シグナル】
0ラインを相場の強弱分岐点とする
ROCが0以上の時は強気相場と判断、
ROCが0以下の時は弱気相場と判断
ROCの逆行現象(トレンドの終息又はトレンド転換のサイン)
価格は上昇(下降)しているがROCは下降(上昇)しROCが値動きと逆行している状態 (相場が天井圏/底値圏で推移している時の逆行現象の方が信頼度は高い)
//+------------------------------------------------------------------+
//| ROC.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Rate of Change"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
//--- input parameters
input int InpRocPeriod=12; // Period
//--- indicator buffers
double ExtRocBuffer[];
//--- global variable
int ExtRocPeriod;
//+------------------------------------------------------------------+
//| Rate of Change initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- check for input
if(InpRocPeriod<1)
{
ExtRocPeriod=12;
Print("Incorrect value for input variable InpRocPeriod =",InpRocPeriod,
"Indicator will use value =",ExtRocPeriod,"for calculations.");
}
else ExtRocPeriod=InpRocPeriod;
//--- indicator buffers mapping
SetIndexBuffer(0,ExtRocBuffer,INDICATOR_DATA);
//--- set accuracy
IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- name for DataWindow and indicator subwindow label
IndicatorSetString(INDICATOR_SHORTNAME,"ROC("+string(ExtRocPeriod)+")");
//--- sets first bar from what index will be drawn
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtRocPeriod);
//--- initialization done
}
//+------------------------------------------------------------------+
//| Rate of Change |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,const int begin,const double &price[])
{
//--- check for rates count
if(rates_total<ExtRocPeriod)
return(0);
//--- preliminary calculations
int pos=prev_calculated-1; // set calc position
if(pos<ExtRocPeriod)
pos=ExtRocPeriod;
//--- the main loop of calculations
for(int i=pos;i<rates_total;i++)
{
if(price[i]==0.0)
ExtRocBuffer[i]=0.0;
else
ExtRocBuffer[i]=(price[i]-price[i-ExtRocPeriod])/price[i]*100;
}
//--- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
【表示結果】
Back to Meta Trader








