//+------------------------------------------------------------------+ 
//|   TRO_STOPPING_VOLUME                                            | 
//|                                                                  | 
//|   Copyright © 2009, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|   All my indicators should be considered donationware. That is   |
//|   you are free to use them for your personal use, and are        |
//|   under no obligation to pay for them. However, if you do find   |
//|   this or any of my other indicators help you with your trading  |
//|   then any Gift or Donation as a show of appreciation is         |
//|   gratefully accepted.                                           |
//|                                                                  |
//|   Gifts or Donations also keep me motivated in producing more    |
//|   great free indicators. :-)                                     |
//|                                                                  |
//|   PayPal - THERUMPLEDONE@GMAIL.COM                               |  
//+------------------------------------------------------------------+ 
//| Use http://therumpledone.mbtrading.com/fx/ as your forex broker  |  
//| ...tell them therumpledone sent you!                             |  
//+------------------------------------------------------------------+ 
/*
// http://emini-watch.com/tradestation-easylanguage-code/400/

Stopping Volume Pattern (Emini 5 minute)

Professional profit taking is occurring when the following conditions are met:

    * Volume is greater than the previous bar’s volume
    * Range is less than the previous bar’s range
    * A new high is made (in an uptrend) or a new low (in a downtrend), and
    * Closes off the highs (in an uptrend) or off the lows (in a downtrend)

The reduction in the bar’s range is the real key. 
It shows that additional selling (in an uptrend) or additional buying (in a downtrend) 
is keeping the bar’s range low. So Professional traders are taking profits and/or 
"fading" the current trend.

You will almost always see Stopping Volume patterns leading up to a market turning point. 
However, if the trend is strong it might take several Stopping Volume patterns in a row 
to slow the trend. Remember, most turning points are Stopping Volume patterns, 
but not all Stopping Volume patterns are turning points!

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

#property indicator_chart_window
#property indicator_buffers 2

 
extern bool   Send.Mail      = false ;
extern bool   Sound.Alert    = false ;
 
extern color StopVolHighColor = DeepSkyBlue;
extern color StopVolLowColor  = DeepPink;
extern color NoSignalColor    = DimGray;


extern int   StopVolHighSymbol = 251 ;
extern int   StopVolLowSymbol  = 251 ;

extern int   SymbolWidth  = 5 ;

//+------------------------------------------------------------------+
 
double BufUp[], BufDn[];

string symbol, tChartPeriod,  tShortName ;  
int    digits, period, digits2  ; 
double point ;

double  cVOLUME, pVOLUME, H, L, H1, L1, cRANGE, pRANGE;

bool StopVolLow, StopVolHigh, oneHigh = false , oneLow = false ; 
 

datetime Trigger ; 
 
//+------------------------------------------------------------------+
int init()
  {
  
   period       =  Period() ;    
   symbol       =  Symbol() ;
   digits       =  Digits ;   
   point        =  Point ;
     
//---- indicators
     
     
      SetIndexBuffer(0,BufUp);
      SetIndexStyle(0,DRAW_ARROW,0,SymbolWidth,StopVolHighColor);
      SetIndexArrow(0, StopVolHighSymbol);
      SetIndexLabel(0,"StopVolUp");
      
      SetIndexBuffer(1,BufDn);
      SetIndexStyle(1,DRAW_ARROW,0,SymbolWidth,StopVolLowColor);
      SetIndexArrow(1, StopVolLowSymbol);
      SetIndexLabel(1,"StopVolDn");
       

//----
   return(0);
  } 
//+------------------------------------------------------------------+
int deinit()
  {
//----
  
//----
   return(0);
  } 
//+------------------------------------------------------------------+
int start()
  {
    
   int limit;
   int counted_bars=IndicatorCounted();
   
//---- last counted bar will be recounted

   if(counted_bars>0) counted_bars--;
   
   limit = Bars - counted_bars - 1; //Bars-counted_bars;
   


   for(int i=limit; i>=0; i--)   
   {
      cVOLUME = iVolume(symbol,period,i); 
      pVOLUME = iVolume(symbol,period,i+1);  
   
      H = iHigh(symbol,period,i);
      L = iLow(symbol,period,i);

      H1 = iHigh(symbol,period,i+1);
      L1 = iLow(symbol,period,i+1); 
  
      cRANGE = H - L ;
      pRANGE = H1 - L1 ;     

      StopVolLow  = cVOLUME > pVOLUME && cRANGE < pRANGE && L < L1 ;   
      StopVolHigh = cVOLUME > pVOLUME && cRANGE < pRANGE && H > H1 ; 
      
      while(true)
      {
         if (StopVolLow ){ oneLow  = true ; BufDn[i] = L ;  BufUp[i] = EMPTY_VALUE ; break ; }
         if (StopVolHigh){ oneHigh = true ; BufUp[i] = H ;  BufDn[i] = EMPTY_VALUE ; break ; }
         BufUp[i] = EMPTY_VALUE ; BufDn[i] = EMPTY_VALUE ; break ;
 
      } // while
          
  } // for
  
  if( Sound.Alert ) { DoAlert() ; }
  
//----


   WindowRedraw() ;
   
    
//----
   return(0);
}
  
//+------------------------------------------------------------------+
void DoAlert()    
{

if ( Trigger != Time[0] ) 
{
  if( Sound.Alert )
  {
    if( StopVolHigh ) { Trigger = Time[0] ; Alert(symbol,"  ",  " Stop Volume High " + DoubleToStr(Close[0] ,digits)); }
    if( StopVolLow )  { Trigger = Time[0] ; Alert(symbol,"  ",  " Stop Volume Low "+ DoubleToStr(Close[0] ,digits)); }     
  }
  
  if( Send.Mail )
  {
    if( StopVolHigh ) { Trigger = Time[0] ; SendMail(symbol,  "Stop Volume High "); }
    if( StopVolLow )  { Trigger = Time[0] ; SendMail(symbol,  "Stop Volume Low "); }     
  }  
  
} // if


} // void
//+------------------------------------------------------------------+

/*
   i = 0 ;
Comment(
"i " , i , "\n" ,
"oneLow " , oneLow , "\n" ,
"oneHigh " , oneHigh , "\n" ,
"StopVolLow " , StopVolLow , "\n" ,
"StopVolHigh " , StopVolHigh , "\n" ,
"BufDn[i] " , DoubleToStr(BufDn[i],Digits) , "\n" ,
"BufUp[i] " , DoubleToStr(BufUp[i],Digits) , "\n" ,
 
"") ;
      
      BufUp[i] = EMPTY_VALUE ; 
      BufDn[i] = EMPTY_VALUE ;
   
   
      
*/