MACD_D3X





//+------------------------------------------------------------------+
//|   MACD_D3X                                                  MACD |
//+------------------------------------------------------------------+
// This is the correct computation and display of MACD !
// fxtsd.com2007 ki
#property copyright ""
#property link      ""

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 DarkSlateGray
#property indicator_color2 Gold
#property indicator_color3 DodgerBlue
#property indicator_color4 Red  
#property indicator_style2 2
#property indicator_level1 0.002
#property indicator_level2 -0.002
#property indicator_levelcolor DarkSlateGray
#property indicator_levelstyle 2

//---- input parameters
extern int       FastMA1Period=5;
extern int       FastMA2Period=13;
extern int       MidMAPeriod =34;
extern int       SlowMAPeriod=55;

//---- buffers
double FastMA1LineBuffer[];
double FastMA2LineBuffer[];
double MidMALineBuffer[];
double MACDLineBuffer[];
double HistogramBuffer[];

//---- variables

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
   //---- indicators
    IndicatorBuffers( 4 );

   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,FastMA1LineBuffer);
   SetIndexDrawBegin(3,SlowMAPeriod+MidMAPeriod);
   
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,FastMA2LineBuffer);
   SetIndexDrawBegin(2,SlowMAPeriod+MidMAPeriod);

   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,MidMALineBuffer);
   SetIndexDrawBegin(1,SlowMAPeriod+MidMAPeriod);

   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,HistogramBuffer);
   SetIndexDrawBegin(0,SlowMAPeriod+MidMAPeriod);
   //---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD_D3 ("+FastMA1Period+","+FastMA2Period+","+MidMAPeriod+","+SlowMAPeriod+")");
   SetIndexLabel(1,"MACD_MidMAsig");
   SetIndexLabel(0,"MACD_MidMA");
   SetIndexLabel(2,"MACD_FastMA2");
   SetIndexLabel(3,"MACD_FastMA1");



   //----
   //----
   return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   //---- 
   //----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int limit;
   int counted_bars = IndicatorCounted();
   //---- check for possible errors
   if (counted_bars<0) return(-1);
   //---- last counted bar will be recounted
   if (counted_bars>0) counted_bars--;
   limit = Bars - counted_bars;

   for(int i=limit; i>=0; i--)
   {
      FastMA1LineBuffer[i] = iMA(NULL,0,FastMA1Period,0,MODE_LWMA,PRICE_CLOSE,i) - iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
      FastMA2LineBuffer[i] = iMA(NULL,0,FastMA2Period,0,MODE_LWMA,PRICE_CLOSE,i) - iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
//      MidMALineBuffer[i] = iMA(NULL,0,MidMAPeriod,0,MODE_EMA,PRICE_CLOSE,i) - iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
      HistogramBuffer[i] =  iMA(NULL,0,MidMAPeriod,0,MODE_EMA,PRICE_CLOSE,i) - iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
     }
   for(i=limit; i>=0; i--)
     {
     MidMALineBuffer[i] = iMAOnArray(HistogramBuffer,0,13,0,MODE_SMA,i);
//     HistogramBuffer[i] =  iMA(NULL,0,FastMA2Period,0,MODE_EMA,PRICE_CLOSE,i) - iMA(NULL,0,MidMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
      }

   //----
   return(0);
}
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:



Indicator Curves created:

Implements a curve of type DRAW_LINE

Implements a curve of type DRAW_HISTOGRAM

Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features: