诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

指标 MACD_Trad_3

MACD_Trad_3指标根据MACD和收盘价的特殊算法在主图创建另类均线。

MACD_Trad_3指标图表:MACD_Trad_3指标

MACD_Trad_3指标源码:

//+------------------------------------------------------------------+
//|                                                  MACD_Trad_3.mq4 |
//|                                     Copyright @2007, Robert Hill |
//+------------------------------------------------------------------+
#property  copyright "Copyright @2004, MetaQuotes Software Corp."
#property  link      "http://www.125808047.com/"
#property strict

#property  indicator_chart_window
#property  indicator_buffers 3
#property  indicator_color1  Silver
#property  indicator_color2  Red
#property  indicator_color3  Blue
#property  indicator_width1  2

input int FastEMA=12;
input int SlowEMA=26;
input int SignalSMA=9;

double     MacdBuffer[];
double     SignalBuffer[];
double     HistoBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit(void)
  {
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_NONE);
   SetIndexStyle(2,DRAW_NONE);
   SetIndexDrawBegin(1,SignalSMA);
   IndicatorDigits(Digits+1);

   SetIndexBuffer(0,MacdBuffer);
   SetIndexBuffer(1,SignalBuffer);
   SetIndexBuffer(2,HistoBuffer);

   IndicatorShortName("MACD("+IntegerToString(FastEMA)+","+IntegerToString(SlowEMA)+","+IntegerToString(SignalSMA)+")");
   SetIndexLabel(0,"MACD YO");
   SetIndexLabel(1,"Signal YO");
   SetIndexLabel(2,"H I S T O :):)");
   Comment("www.125808047.com");
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
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[])
  {
   int i,limit;
   if(rates_total<=SignalSMA)
      return(0);

   limit=rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;

   for(i=0; i<limit; i++)
      MacdBuffer[i]=Close[i]+(iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i));

   for(i=0; i<limit; i++)
      SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);

   for(i=0; i<limit; i++)
      HistoBuffer[i]=Close[i]+(MacdBuffer[i]-SignalBuffer[i]);
      
   for(i=0; i<limit; i++)
      MacdBuffer[i]=iMAOnArray(HistoBuffer,Bars,SignalSMA,0,MODE_SMA,i);
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 指标 MACD_Trad_3
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏