//+------------------------------------------------------------------+
//|                                                  Volumes_mod.mq4 |
//|                                                silverkaz@mail.ru |
//+------------------------------------------------------------------+
//---- indicator settings
#property  indicator_separate_window
#property indicator_minimum 0
#property indicator_buffers 4
#property indicator_color1  clrBlack
#property indicator_color2  clrGreen
#property indicator_color3  clrRed
#property indicator_color4  clrGray
#property indicator_width2  3
#property indicator_width3  3
#property indicator_width4  3
//---- indicator buffers
double ExtVolumesBuffer[];
double ExtVolumesUpBuffer[];
double ExtVolumesDownBuffer[];
double ExtVolumesFlatBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtVolumesBuffer);       
   SetIndexBuffer(1,ExtVolumesUpBuffer);
   SetIndexBuffer(2,ExtVolumesDownBuffer);
   SetIndexBuffer(3,ExtVolumesFlatBuffer);
//---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexStyle(4,DRAW_HISTOGRAM);
//---- sets default precision format for indicators visualization
   IndicatorDigits(0);   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Volumes_mod");
   SetIndexLabel(0,"Volumes_mod");      
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,NULL);
//---- sets drawing line empty value
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);       
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Volumes                                                          |
//+------------------------------------------------------------------+
int start()
{
//----
   int i, nLimit, nCountedBars;
   nCountedBars = IndicatorCounted();
   if(nCountedBars > 0) nCountedBars--;
   nLimit = Bars - nCountedBars;
//----
   for(i = 0; i < nLimit; i++)
   {
      double dVolume = Volume[i];
      if(i == Bars-1 || Close[i] > Open[i])
      {
         ExtVolumesBuffer[i] = dVolume;
         ExtVolumesUpBuffer[i] = dVolume;
         ExtVolumesDownBuffer[i] = 0.0; 
         ExtVolumesFlatBuffer[i] = 0.0;       
      }
      else if(i == Bars-1 || Close[i] < Open[i]) 
      {
         ExtVolumesBuffer[i] = dVolume;
         ExtVolumesUpBuffer[i] = 0.0;
         ExtVolumesDownBuffer[i] = dVolume;
         ExtVolumesFlatBuffer[i] = 0.0;        
      }
      else
      {
         ExtVolumesBuffer[i] = dVolume;
         ExtVolumesUpBuffer[i] = 0.0;
         ExtVolumesDownBuffer[i] = 0.0;
         ExtVolumesFlatBuffer[i] = dVolume;        
      } 
   }        
//---- done
   return(0);
}
//+------------------------------------------------------------------+