PDI_001





                                            
//+------------------------------------------------------------------+
//|                                                         PDI.mq4  |
//|                                      Copyright © 2007, Melpheos  |
//|                                     http://www.forexfactory.com/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2007, Melpheos"
#property  link      "http://www.forexfactory.com/"

//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#property  indicator_width1  2
#property  indicator_color2  Red
#property  indicator_width2  2


//---- indicator parameters
extern int FastMA=50;
extern int FastMA_Type = 1;
extern int SlowMA=100;
extern int SlowMA_Type = 1;

//---- indicator buffers
double     DistanceBuffer[];
double     DirectionBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexDrawBegin(0,DistanceBuffer);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexDrawBegin(1,DirectionBuffer);
//   IndicatorDigits(Digits+2);
//---- 2 indicator buffers mapping
   SetIndexBuffer(0,DistanceBuffer);
   SetIndexBuffer(1,DirectionBuffer);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("PDI("+FastMA+","+SlowMA+")");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Calculation                                                      |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(int i=0; i<limit; i++)
      DistanceBuffer[i]= (( Close[i] - iMA(NULL,0,FastMA,0,FastMA_Type,PRICE_CLOSE,i))/5);
   for(i=0; i<limit; i++)
      DirectionBuffer[i]=( iMA(NULL,0,SlowMA,0,SlowMA_Type,PRICE_CLOSE,i)-iMA(NULL,0,SlowMA,0,SlowMA_Type,PRICE_CLOSE,i+1))*2;


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





Sample





Analysis



Market Information Used:

Series array that contains close prices for each bar


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: