【解説】 【MQL5 community】 Accumulation/Distribution (累積 / 分散): 「累積(買い集め)」や「分散(売り集め)」の傾向を参考にして、 通貨ペアの需要と供給を測る指標である。 これは出来高は価格に先行するという概念に基づいている。 この指標は累積騰落出来高(OBV)の変形ともいえる。 どちらの指標も、買い・売りのどちらの出来高が高いかをみることによって価格変動の確認として利用される。
Accumulation/Distribution指標の示す値が上昇しているとき、 累積(買い集め)が起こっていると考えられる。 出来高が占める割合が価格の上昇と関係しているからである。 指標が下降しているとき、分散(売り集め)が起こっていると考えられる。 このようにA/D指標は出来高に方向性を与える。 トレンドが持続傾向もしくは安定トレンドであるためには、出来高の方向は現在の価格トレンドの方向と同じであるべきだと考えられている。
実際には、A/D指標は価格と逆方向に向かっている状況をみつけるのに利用される。 このような状況をダイバージェンスといい、 価格の反転が近いことを意味する。 一般にダイバージェンスが生じたら、 価格はA/Dが動く方向と同方向に動く傾向がある。 またA/Dは買い圧力・売り圧力を示す。 このように、指標が上昇していて、価格が下落していれば、 価格の反転が予測される。価格は最終的に買い圧力に負け、 上昇することとなる。
【計算法】
N期のA/D =((N期の終値 − N期の安値) − (N期の高値 − N期の終値) )/ (N期の高値 − N期の低値)}×N期の出来高 + N−1期のA/D
日々の出来高を累計に加算・減算する。 終値が高値の方に近ければ、出来高は加算され、安値に近ければ、減算される。 数式からも分かるが, 仮にN期の高値と低い値が等しい場合はカウントせず。
【シグナル】
「買い」: ローソク足が下落基調または横這いなのに、A/Dが逆行して上昇してるとき。
「売り」: ローソク足が上昇基調または横這いなのに、A/Dが逆行して下落してるとき。
相場の方向性とADの方向性を確認する事で、 相場への売り圧力・買い圧力が掛かっているかどうかを判断します。 もし、相場とA/Dが同じ方向を保っていれば、相場の動きは安定しており、もし相場が上がっているときにA/Dが下がっていれば、「売り圧力」が掛かっていて売り時であると判断します。 逆に相場が下がっていてA/Dが上がっていれば、「買い圧力」が掛かっていて買い時であると判断します。
//+------------------------------------------------------------------+
//| AD.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Accumulation/Distribution"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
#property indicator_label1 "A/D"
//--- input params
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volume type
//---- buffers
double ExtADbuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//--- indicator digits
IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- indicator short name
IndicatorSetString(INDICATOR_SHORTNAME,"A/D");
//---- index buffer
SetIndexBuffer(0,ExtADbuffer);
//--- set index draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| Accumulation/Distribution |
//+------------------------------------------------------------------+
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[])
{
//--- check for bars count
if(rates_total<2)
return(0); //exit with zero result
//--- get current position
int pos=prev_calculated-1;
if(pos<0) pos=0;
//--- calculate with appropriate volumes
if(InpVolumeType==VOLUME_TICK)
Calculate(rates_total,pos,High,Low,Close,TickVolume);
else
Calculate(rates_total,pos,High,Low,Close,Volume);
//----
return(rates_total);
}
//+------------------------------------------------------------------+
//| Calculating with selected volume |
//+------------------------------------------------------------------+
void Calculate(const int rates_total,const int pos,
const double &High[],
const double &Low[],
const double &Close[],
const long &Volume[])
{
double hi,lo,cl;
//--- main cycle
for(int i=pos;i<rates_total;i++)
{
//--- get some data from arrays
hi=High[i];
lo=Low[i];
cl=Close[i];
//--- calculate new AD
double sum=(cl-lo)-(hi-cl);
if(hi==lo) sum=0.0;
else sum=(sum/(hi-lo))*Volume[i];
if(i>0) sum+=ExtADbuffer[i-1];
ExtADbuffer[i]=sum;
}
//----
}
//+------------------------------------------------------------------+
【表示結果】

上図ではADのトレンドは相場のトレンドとほぼ一緒ですが、
下図ではADのトレンドは相場のトレンドと異なります、だからと言ってボトムで買ったら損する。
//+------------------------------------------------------------------+
//| W_AD.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property description "Larry Williams' Accumulation/Distribution"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots 1
#property indicator_type1 DRAW_LINE
#property indicator_color1 LightSeaGreen
//---- buffers
double ExtWADBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit()
{
//---- define buffer
SetIndexBuffer(0,ExtWADBuffer);
//--- set draw begin
PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,1);
//--- indicator name
IndicatorSetString(INDICATOR_SHORTNAME,"W_A/D");
//--- round settings
IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//---- OnInit done
}
//+------------------------------------------------------------------+
//| 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 &TickVolume[],
const long &Volume[],
const int &Spread[])
{
//---
if(rates_total<2)
return(0);
//--- start working
int pos=prev_calculated-1;
//--- correct position, set initial value
if(pos<=0)
{
pos=1;
ExtWADBuffer[0]=0.0;
}
//--- main cycle
for(int i=pos;i<rates_total;i++)
{
//--- get data
double hi=High[i];
double lo=Low[i];
double cl=Close[i];
double prev_cl=Close[i-1];
//--- calculate TRH and TRL
double trh=MathMax(hi,prev_cl);
double trl=MathMin(lo,prev_cl);
//--- calculate WA/D
if(IsEqualDoubles(cl,prev_cl,_Point))
ExtWADBuffer[i]=ExtWADBuffer[i-1];
else
{
if(cl>prev_cl)
ExtWADBuffer[i]=ExtWADBuffer[i-1]+cl-trl;
else
ExtWADBuffer[i]=ExtWADBuffer[i-1]+cl-trh;
}
}
//---- OnCalculate done. Return new prev_calculated.
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool IsEqualDoubles(double d1,double d2,double epsilon)
{
if(epsilon<0.0) epsilon=-epsilon;
if(epsilon>0.1) epsilon=0.00001;
//---
double diff=d1-d2;
if(diff>epsilon || diff<-epsilon) return(false);
//---
return(true);
}
//+------------------------------------------------------------------+
【表示結果】

Back to Meta Trader







