//+------------------------------------------------------------------+ 
//|   _TRO_VOLUME_EZ                                                 | 
//|                                                                  | 
//|   Copyright © 2008, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|                                                                  |
//|   therumpledone@gmail.com                                         |  
//+------------------------------------------------------------------+ 
/*



VOLUME over X bars 

TOP LEFT   MAXIMUM Volume / MINIMUM Volume

TOP RIGHT  This shows the average volume reached during the X bars

BIG NUMBER   the current VOLUME  AND % of the average VOLUME.

BOTTOM LEFT  = # bars above / below current volume.  

BOTTOM RIGHT  = # bars above / below average volume.  



*/
#property  copyright "Copyright © 2008, Avery T. Horton, Jr. aka TRO" 
#property  link      "http://www.therumpledone.com/" 

//---- indicator settings 
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_minimum 0
#property indicator_maximum 1



//---- indicator parameters  
//extern int   Threshold       = 20; 

extern int win           = 0;
extern int price.x.offset= -500 ; //250
extern int price.y.offset= -160 ; //-160

extern int   Chart_Period    = PERIOD_M1;

extern int   MaxBars         = 60;

extern color ColorHeading    =  Gray ; 
extern color ColorVolume     = LightGray ; 
extern color ThresholdColor  = LimeGreen; 
extern color ColorABAvg      =  DarkViolet ;    
extern color ColorAvg        =  Orange ;  
extern color ColorABCur      =  Blue ; 
extern color ColorMinMax     =  Chocolate ; 


//---- indicator buffers 

double     MaxVolume = 0 ; 
double     MinVolume = 0 ; 
double     AvgVolume = 0 ; 
double     xVolume   = 0 ; 
double     tVolume   = 0 ; 


//---- buffers


double zVolume = 0;

bool  show.info       = true;
bool  ShowChart       = true; 

double   AboveAvg, BelowAvg, AboveCur, BelowCur ;

double xRet, close ;
double xRetPct;  

//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init() 
  { 
   
   if(Chart_Period == 0 ) { Chart_Period = Period() ;}
   return(0); 
  } 

int deinit() 
{ 

ObjectsDeleteAll( win);    
    
}  

//+------------------------------------------------------------------+ 
//| Volume                                                            | 
//+------------------------------------------------------------------+ 
int start() 
  { 


    MaxVolume = 0 ; 
    MinVolume = 999999999 ; 

   double HighVal,LowVal; 
   int limit; 
   int counted_bars=IndicatorCounted(); 
    
//---- last counted bar will be recounted 
   if(counted_bars>0) counted_bars--; 
   if(counted_bars<0) return(-1); 
   

   AboveAvg = 0 ; 
   BelowAvg = 0 ; 
   AboveCur = 0 ; 
   BelowCur  = 0 ;
  
   limit = MaxBars + 1;  

//---- Volume counted in the 1-st buffer 

		double buf_tmp = 0 ;
		int z = 0 ;
     
    zVolume = iVolume(NULL,Chart_Period,0) ;

   for(int i=1; i<limit; i++) 
   { 

     xVolume = iVolume(NULL,Chart_Period,i) ; // Volume

     tVolume = xVolume  ; // Volume
     
     buf_tmp =  buf_tmp + xVolume ;
 
     if( tVolume > MaxVolume ) {MaxVolume = tVolume  ; }
     if( tVolume < MinVolume ) {MinVolume = tVolume  ; }  
    
     if( tVolume > AvgVolume ) {AboveAvg = AboveAvg + 1  ; }
     if( tVolume < AvgVolume ) {BelowAvg = BelowAvg + 1  ; }     

     if( tVolume > zVolume ) {AboveCur = AboveCur + 1  ; }
     if( tVolume < zVolume ) {BelowCur = BelowCur + 1  ; }     
                 
   } 

   AvgVolume = buf_tmp / MaxBars  ; // average Volume   
   
   xRetPct =  ( 100 ) * ( zVolume / AvgVolume )  ;  
    

//} 
 
//+------------------------------------------------------------------+ 
   
//void DoShowInfo()

//{

string tPeriod = " "+TimeFrameToString( Chart_Period ) ;

if ( zVolume > AvgVolume ) { color VolumeColor = ThresholdColor ; } else { VolumeColor = ColorVolume   ; }

   ObjectCreate("VOL630", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("VOL630"," VOLUME "+MaxBars, 20, "Arial Bold", ColorHeading);
   ObjectSet("VOL630", OBJPROP_CORNER, 0);
   ObjectSet("VOL630", OBJPROP_XDISTANCE, 760+price.x.offset);
   ObjectSet("VOL630", OBJPROP_YDISTANCE, 160+price.y.offset);

string  VOL629 = DoubleToStr( MaxVolume ,0) + " / " + DoubleToStr( MinVolume ,0) ;    

   ObjectCreate("VOL629", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("VOL629",VOL629, 15, "Arial Bold", ColorMinMax  );
   ObjectSet("VOL629", OBJPROP_CORNER, 0);
   ObjectSet("VOL629", OBJPROP_XDISTANCE, 770+price.x.offset);
   ObjectSet("VOL629", OBJPROP_YDISTANCE, 197+price.y.offset);

string  VOL629b = DoubleToStr( AboveCur ,0) + " / " + DoubleToStr( BelowCur ,0) ; 
 
  
   ObjectCreate("VOL629b", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("VOL629b", VOL629b , 15, "Arial Bold", ColorABCur );
   ObjectSet("VOL629b", OBJPROP_CORNER, 0);
   ObjectSet("VOL629b", OBJPROP_XDISTANCE, 770+price.x.offset);
   ObjectSet("VOL629b", OBJPROP_YDISTANCE, 260+price.y.offset);                 
                   
                   
string  VOL631 = DoubleToStr(zVolume,0)+tPeriod + " " + DoubleToStr(xRetPct,0) + "%" ;
                   
   ObjectCreate("VOL631", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("VOL631", VOL631 , 25, "Arial Bold", VolumeColor );
   ObjectSet("VOL631", OBJPROP_CORNER, 0);
   ObjectSet("VOL631", OBJPROP_XDISTANCE, 765+price.x.offset); // 765
   ObjectSet("VOL631", OBJPROP_YDISTANCE, 220+price.y.offset); 
           

   ObjectCreate("VOL632", OBJ_LABEL, win, 0, 0);   // 
   ObjectSetText("VOL632",DoubleToStr( AvgVolume ,2), 15, "Arial Bold", ColorAvg); // VolumeBuffer2[0] buf0[0]
   ObjectSet("VOL632", OBJPROP_CORNER, 0);
   ObjectSet("VOL632", OBJPROP_XDISTANCE, 880+price.x.offset);
   ObjectSet("VOL632", OBJPROP_YDISTANCE, 197+price.y.offset);
                 
string  VOL634 = DoubleToStr( AboveAvg ,0) + " / " + DoubleToStr( BelowAvg ,0) ;                
           
   ObjectCreate("VOL634", OBJ_LABEL, win, 0, 0);
   ObjectSetText("VOL634", VOL634 , 15, "Arial Bold",  ColorABAvg);
   ObjectSet("VOL634", OBJPROP_CORNER, 0);
   ObjectSet("VOL634", OBJPROP_XDISTANCE, 880+price.x.offset);
   ObjectSet("VOL634", OBJPROP_YDISTANCE, 260+price.y.offset);    
    

   WindowRedraw();    
 
//} 

   return(0); 
} 

//+------------------------------------------------------------------+

 
string TimeFrameToString(int tf)
{
   string tfs;
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN1";
   }
   return(tfs); 
}
 
//+------------------------------------------------------------------+