【解説】【MQL5 community】 ZeroLag MACD : 短期と中期の指数平滑移動平均(EMA)がどの程度離れているか、 どの程度近づいたかを分析し、売買シグナルを見極める手法。 通常のMACDと基本的な計算法を用いるものの、少し異なる。 特に価格が上昇している場合は, 緑色, 逆に下落している場合は, 赤色.
【計算法】
速い移動平均:
ZeroLagEMAp = FastEMABuffer[i] + FastEMABuffer[i] - val[i];
遅い移動平均:
ZeroLagEMAq = SlowEMABuffer[i] + SlowEMABuffer[i] - val1[i];
MACD:
MACDBuffer[i]=ZeroLagEMAp-ZeroLagEMAq;
シグナル:
SignalBuffer[i]=SignalEMABuffer[i]+SignalEMABuffer[i]-val3[i];
【シグナル】
一般にMACDがMACDシグナルを下から上に抜けたら買いシグナル、 上から下に抜けたら売りシグナル。
//+------------------------------------------------------------------+ //| ZeroLag MACD.mq5 | //| avoitenko | //| https://login.mql5.com/en/users/avoitenko | //+------------------------------------------------------------------+ #property copyright "avoitenko" #property link "https://login.mql5.com/en/users/avoitenko" #property version "2.00" #include <MovingAverages.mqh> #property indicator_separate_window #property indicator_buffers 9 #property indicator_plots 2 //--- plot MACDBuffer #property indicator_label1 "Main" #property indicator_type1 DRAW_HISTOGRAM #property indicator_color1 Blue #property indicator_style1 STYLE_SOLID #property indicator_width1 2 //--- plot SignalBuffer #property indicator_label2 "Signal" #property indicator_type2 DRAW_LINE #property indicator_color2 Red #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //---- input parameters input int FastEMA = 12; // Fast EMA input int SlowEMA = 26; // Slow EMA input int SignalEMA = 9;// Signal EMA input ENUM_APPLIED_PRICE Price=PRICE_CLOSE;// Apply to //---- buffers double MACDBuffer[]; double SignalBuffer[]; double FastEMABuffer[]; double SlowEMABuffer[]; double SignalEMABuffer[]; double val[]; double val1[]; double val2[]; double val3[]; int limit; //indicator handles int maHandle1,maHandle2; //+------------------------------------------------------------------+ int OnInit() //+------------------------------------------------------------------+ { //--- indicator buffers mapping SetIndexBuffer(0,MACDBuffer,INDICATOR_DATA); SetIndexBuffer(1,SignalBuffer,INDICATOR_DATA); SetIndexBuffer(2,FastEMABuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(3,SlowEMABuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(4,SignalEMABuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(5,val,INDICATOR_CALCULATIONS); SetIndexBuffer(6,val1,INDICATOR_CALCULATIONS); SetIndexBuffer(7,val2,INDICATOR_CALCULATIONS); SetIndexBuffer(8,val3,INDICATOR_CALCULATIONS); PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,EMPTY_VALUE); PlotIndexSetInteger(0,PLOT_SHIFT,0); PlotIndexSetInteger(1,PLOT_SHIFT,0); PlotIndexSetString(0,PLOT_LABEL,"MACD"); PlotIndexSetString(1,PLOT_LABEL,"Signal"); IndicatorSetString(INDICATOR_SHORTNAME,"ZeroLag MACD("+IntegerToString(FastEMA) +","+IntegerToString(SlowEMA)+","+IntegerToString(SignalEMA)+")"); ArraySetAsSeries(MACDBuffer,true); ArraySetAsSeries(SignalBuffer,true); ArraySetAsSeries(FastEMABuffer,true); ArraySetAsSeries(SlowEMABuffer,true); ArraySetAsSeries(SignalEMABuffer,true); ArraySetAsSeries(val,true); ArraySetAsSeries(val1,true); ArraySetAsSeries(val2,true); ArraySetAsSeries(val3,true); maHandle1 = iMA(_Symbol, PERIOD_CURRENT, FastEMA, 0, MODE_EMA, Price); maHandle2 = iMA(_Symbol, PERIOD_CURRENT, SlowEMA, 0, MODE_EMA, Price); //--- return(0); } //+------------------------------------------------------------------+ 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[], const long &volume[], const int &spread[]) //+------------------------------------------------------------------+ { //--- if(rates_total<prev_calculated) return(0); limit=rates_total-prev_calculated; if(CopyBuffer(maHandle1, MAIN_LINE, 0, rates_total, FastEMABuffer) < 0) return(0); if(CopyBuffer(maHandle2, MAIN_LINE, 0, rates_total, SlowEMABuffer) < 0) return(0); ExponentialMAOnBuffer(rates_total,prev_calculated,0,FastEMA,FastEMABuffer,val); // SimpleMAOnBuffer(rates_total,prev_calculated,0,FastEMA,FastEMABuffer,val); ExponentialMAOnBuffer(rates_total,prev_calculated,0,SlowEMA,SlowEMABuffer,val1); // SimpleMAOnBuffer(rates_total,prev_calculated,0,FastEMA,SlowEMABuffer,val1); for(int i=0; i<limit; i++) { double ZeroLagEMAp = FastEMABuffer[i] + FastEMABuffer[i] - val[i]; double ZeroLagEMAq = SlowEMABuffer[i] + SlowEMABuffer[i] - val1[i]; MACDBuffer[i]=ZeroLagEMAp-ZeroLagEMAq; } ExponentialMAOnBuffer(rates_total,prev_calculated,0,SignalEMA,MACDBuffer,val2); ArrayCopy(SignalEMABuffer,val2,0,0,limit); ExponentialMAOnBuffer(rates_total,prev_calculated,0,SignalEMA,SignalEMABuffer,val3); for(int i=0; i<limit; i++) { SignalBuffer[i]=SignalEMABuffer[i]+SignalEMABuffer[i]-val3[i]; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ void OnDeinit(const int reason) //+------------------------------------------------------------------+ { IndicatorRelease(maHandle1); IndicatorRelease(maHandle2); } //+------------------------------------------------------------------+
【表示結果】
Back to Meta Trader