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

MACD类指标 Macd_Correct

Macd_Correct指标属于MACD的一种优化。

Macd_Correct指标图表:Macd_Correct指标

Macd_Correct指标源码:

//+------------------------------------------------------------------+
//|                                                 Macd_Correct.mq4 |
//|                                Copyright @2005, David W. Thomas |
//+------------------------------------------------------------------+
#property copyright "Copyright @2005, David W. Thomas"
#property link      "http://www.125808047.com/"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Green

extern int IndexMultiplier     = 0;
extern string separator0 = "-------------------------";
extern int Fast_MAPeriod       =  12;
extern int Fast_MA_Shift       =  0;
extern int Fast_MA_Method      =  1; 
extern int Fast_Applied_Price  =  0; 
extern string separator1 = "-------------------------";
extern int Slow_MAPeriod       =  26;
extern int Slow_MA_Shift       =  0;
extern int Slow_MA_Method      =  1; 
extern int Slow_Applied_Price  =  0; 
extern string separator2 = "-------------------------";
extern int SignalPeriod        =  9;
extern string separator3 = "-------------------------";
extern int MacdWidth           =  2;
extern int SignalWidth         =  1;
extern int HistogramWidth      =  3;
extern int ShowBars            =  1000;

double MACDLineBuffer[];
double SignalLineBuffer[];
double HistogramBuffer[];

double alpha = 0;
double alpha_1 = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
{
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
      
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,HistogramWidth);
   SetIndexBuffer(0,HistogramBuffer);
   SetIndexDrawBegin(0,Slow_MAPeriod+SignalPeriod);
   SetIndexLabel(0,"Histogram");
   
   SetIndexEmptyValue(1,0.0);
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT,SignalWidth);
   SetIndexBuffer(1,SignalLineBuffer);
   SetIndexDrawBegin(1,Slow_MAPeriod+SignalPeriod);
   SetIndexLabel(1,"Signal");
   
   SetIndexEmptyValue(2,0.0);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,MacdWidth);
   SetIndexBuffer(2,MACDLineBuffer);
   SetIndexDrawBegin(2,Slow_MAPeriod);
   SetIndexLabel(2,"MACD");
   IndicatorShortName("Macd_Correct("+Fast_MAPeriod+","+Slow_MAPeriod+","+SignalPeriod+")");	
	alpha = 2.0 / (SignalPeriod + 1.0);
	alpha_1 = 1.0 - alpha;
   return(0);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+

int deinit()
{
   Comment("www.125808047.com");
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start(){
   if (IndexMultiplier == 0) IndexMultiplier = 1;
   int limit;
   int counted_bars = IndicatorCounted();
   if (counted_bars<0) return(-1);
   if (counted_bars>0) counted_bars--;
   limit = ShowBars;
   if (limit > Bars) limit = Bars - counted_bars;
   for(int i=limit; i>=0; i--)
   {
      MACDLineBuffer[i]   = (iMA(Symbol(),0,Fast_MAPeriod,Fast_MA_Shift,Fast_MA_Method,Fast_Applied_Price,i)
                          - iMA(Symbol(),0,Slow_MAPeriod,Slow_MA_Shift,Slow_MA_Method,Slow_Applied_Price,i))*IndexMultiplier;
      SignalLineBuffer[i] = alpha*MACDLineBuffer[i] + alpha_1*SignalLineBuffer[i+1];
      HistogramBuffer[i]  = MACDLineBuffer[i] - SignalLineBuffer[i];
   }
   return(0);
}
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » MACD类指标 Macd_Correct
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏