//+------------------------------------------------------------------+
//|                                               DMI ADX histogram oscillator.mq4 |
//|                               Copyright © 2012, Gehtsoft USA LLC |
//|                                            http://fxcodebase.com |
//|                                            mario.jemic@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, Gehtsoft USA LLC"
#property link      "http://fxcodebase.com"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Green
#property indicator_color3 Red

 
extern int CalculationPeriod=14;
extern int Mode=0;
extern bool Smoothing = true;
extern int PriceType=0;

double ADX[];
double UP[];
double DOWN[];

int init()
  {
   IndicatorBuffers(3);
   IndicatorShortName("DMI ADX Filter");
   IndicatorDigits(Digits);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ADX);
   
   
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,UP);
   
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexBuffer(2,DOWN);
   
 
   
   return(0);
  }

int deinit()
  {
   return(0);
  }

int start()
 {
  double BarsToCount = 0;
   int bars_counted = IndicatorCounted();
   if(bars_counted < 0)
   {
      return(1);
   }
   else if(bars_counted > 0) 
   {
      bars_counted--;
   }
   int limit = Bars - bars_counted;
   if(BarsToCount>0 && limit>BarsToCount) 
   {
      limit = BarsToCount;
   }
    
	
   for(int i=limit-CalculationPeriod; i>=0; i--)
   {
 
	   double DMI = iADX(NULL, 0, CalculationPeriod, PriceType, MODE_PLUSDI, i)- iADX(NULL, 0, CalculationPeriod, PriceType, MODE_MINUSDI, i);
      
       ADX[i] = iADX(NULL, 0, CalculationPeriod, PriceType, MODE_MAIN, i);
	   
	   if (DMI>0) 
			   {
			   UP[i]= DMI;
			   DOWN[i]=  EMPTY_VALUE;
			   }
			   else
			   {
			   DOWN[i]= DMI;
			   UP[i]=  EMPTY_VALUE;
			   }
	  
  } 
  
  
  
  
   
 return(0);
}

