//+------------------------------------------------------------------+
//|                                                 Delta  Indicator |
//|                                               Copyright © Nefesh |
//|                                         Coded/Verified by Nefesh |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, Nefesh."
#property link      ""
//-----
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1  Black
#property indicator_color2  DodgerBlue
#property indicator_color3  OrangeRed
#property indicator_width2  2
#property indicator_width3  2

//---- input parameters

//---- buffers
double DeltaUp[];
double DeltaDown[];
double Delta[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorShortName("Delta");
   SetIndexLabel(0,"Delta");      
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
      
   SetIndexBuffer(0,Delta);      
   SetIndexBuffer(1,DeltaUp);
   SetIndexBuffer(2,DeltaDown);
      
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
      
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
      
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Volume Delta Indicator                                           |
//+------------------------------------------------------------------+
int start()
  {
   int    i,nLimit,nCountedBars;
//---- bars count that does not changed after last indicator launch.
   nCountedBars=IndicatorCounted();
//---- last counted bar will be recounted
   if(nCountedBars>0) nCountedBars--;
   nLimit=Bars-nCountedBars;
//----
   for(i=0; i<nLimit; i++)
     {
      double dDelta=((Volume[i]+(Close[i]-Open[i])/Point)/2)-(Volume[i]-((Volume[i]+(Close[i]-Open[i])/Point)/2));  //      (UpTicks[i] = (Volume[i] + (Close[i] - Open[i]) / Point) / 2)- (DnTicks[i] = Volume[i] - UpTicks[i])
      if(i==Bars-1 || dDelta>0)
        {
         Delta[i]=dDelta;
         DeltaUp[i]=dDelta;
         DeltaDown[i]=0.0;        
        }
      else
        {
         Delta[i]=dDelta;        
         DeltaUp[i]=0.0;
         DeltaDown[i]=dDelta;        
        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+