【解説】【MQL5 community】 On Balance Volume (オン・バランス・ボリューム): 「出来高は価格に先行する」という 上昇トレンドの前には出来高が増え、 下降トレンドの前には出来高が減るという考えに基づいた指標。 市場の上昇/下降傾向にあわせてOBVが上昇/下降しているときはトレンドが継続中、 OBVが横ばいになったらトレンドは終了と考えます。
【計算法】
OBVは出来高の正・負の累計である。
N期の終値 > N-1期の終値: OBV=N-1期のOBV+N期の出来高,
N期の終値 < N-1期の終値: OBV=N-1期のOBV−N期の出来高,
N期の終値 = N-1期の終値: OBV=N-1期のOBV
【シグナル】
1.価格変化とOBVが同期して上昇・下降していれば、そのトレンドは強い。
2.価格がOBVに先行して上昇・下降するが、OBVは停滞し始めたときは、価格は引き戻される。
3.OBVが価格に先行して上昇・下降するが、価格は停滞し始めたときは、早晩価格は上昇・下降を継続しOBVに追随する。
//+------------------------------------------------------------------+
//| OBV.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "On Balance Volume"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 DodgerBlue
#property indicator_label1 "OBV"
//--- input parametrs
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//---- indicator buffer
double ExtOBVBuffer[];
//+------------------------------------------------------------------+
//| On Balance Volume initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- define indicator buffer
SetIndexBuffer(0,ExtOBVBuffer);
//--- set indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,0);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| On Balance Volume |
//+------------------------------------------------------------------+
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 &TickVolume[],
const long &Volume[],
const int &Spread[])
{
//--- variables
int pos;
double Vol;
//--- check for bars count
if(rates_total<2)
return(0);
//--- starting calculation
pos=prev_calculated-1;
//--- correct position, when it's first iteration
if(pos<1)
{
pos=1;
if(InpVolumeType==VOLUME_TICK)
ExtOBVBuffer[0]=TickVolume[0];
else ExtOBVBuffer[0]=Volume[0];
}
//--- main cycle
if(InpVolumeType==VOLUME_TICK)
CalculateOBV(pos,rates_total,Close,TickVolume);
else
CalculateOBV(pos,rates_total,Close,Volume);
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculate OBV by volume argument |
//+------------------------------------------------------------------+
void CalculateOBV(int StartPosition,
int RatesCount,
const double &ClBuffer[],
const long &VolBuffer[])
{
for(int i=StartPosition;i<RatesCount;i++)
{
//--- get some data
double Volume=VolBuffer[i];
double PrevClose=ClBuffer[i-1];
double CurrClose=ClBuffer[i];
//--- fill ExtOBVBuffer
if(CurrClose<PrevClose) ExtOBVBuffer[i]=ExtOBVBuffer[i-1]-Volume;
else
{
if(CurrClose>PrevClose) ExtOBVBuffer[i]=ExtOBVBuffer[i-1]+Volume;
else ExtOBVBuffer[i]=ExtOBVBuffer[i-1];
}
}
}
//+------------------------------------------------------------------+
【表示結果】
Back to Meta Trader








