//+------------------------------------------------------------------+
//|                                         VOLUME&SPREAD VISUAL.mq4 |
//|                                    Copyright © 2009, FOREXflash. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, FOREXflash Software"
#property link      "http://www.metaquotes.net"
//---- indicator settings
#property  indicator_separate_window
#property indicator_minimum 0
#property indicator_buffers 4
#property indicator_color1  Black
#property indicator_color2  Green
#property indicator_color3  Red
#property indicator_color4  White
#property indicator_width2  2
#property indicator_width3  2
#property indicator_width4  2

extern bool   displayAlert = true;
extern double AlertAtLevel = 50;

//---- indicator buffers
double ExtVolumesBuffer[];
double ExtVolumesUpBuffer[];
double ExtVolumesDownBuffer[];
double SpreadBuffer[];
static datetime lastAlertTime; 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtVolumesBuffer);       
   SetIndexBuffer(1,ExtVolumesUpBuffer);
   SetIndexBuffer(2,ExtVolumesDownBuffer);
   SetIndexBuffer(3,SpreadBuffer);
//---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_LINE,2);
//---- sets default precision format for indicators visualization
   IndicatorDigits(0);   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Volumes");
   SetIndexLabel(0,"Volumes");      
   SetIndexLabel(1,"VOLUME:");
   SetIndexLabel(2,"VOLUME:");
   SetIndexLabel(3,"SPREAD:");
//---- sets drawing line empty value
   SetIndexEmptyValue(1,0.0);
   SetIndexEmptyValue(2,0.0);
   SetIndexEmptyValue(3,0.0); 
      
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Volumes                                                          |
//+------------------------------------------------------------------+
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 dVolume=Volume[i];
      if(i==Bars-1 || dVolume>Volume[i+1])
        {
         ExtVolumesBuffer[i]=dVolume;
         ExtVolumesUpBuffer[i]=dVolume;
         ExtVolumesDownBuffer[i]=0.0;
         SpreadBuffer[i]=((iHigh(NULL,0,i)-(iLow(NULL,0,i))))*100000;    
        }
      else
        {
         ExtVolumesBuffer[i]=dVolume;
         ExtVolumesUpBuffer[i]=0.0;
         ExtVolumesDownBuffer[i]=dVolume;
         SpreadBuffer[i]=((iHigh(NULL,0,i)-(iLow(NULL,0,i))))*100000;
       
        } 
     }
     
if (displayAlert == true && SpreadBuffer[i]>=AlertAtLevel) 
    Alert("Spread bigger than selected level:",SpreadBuffer[i]);          
//---- done
   return(0);
  }

//+------------------------------------------------------------------+