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


#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 win = 0;
extern int price.x.offset= 0 ; 
extern int price.y.offset= 100 ; 


extern int   myFontSize       = 60;

extern int iStochOB = 80 ;
extern int iStochOS = 20 ;

extern int KPeriod=8;
extern int DPeriod=3;
extern int Slowing=3;
extern int MAMethod=0;
extern int PriceField=0; 

extern string Buy_Message  = "BUY" ;
extern string Wait_Message = "WAIT" ;
extern string Sell_Message = "SELL" ;
extern string Rdy_Message  = "GET READY" ;

extern color Buy_color  = Lime;
extern color Wait_color = Yellow;
extern color Sell_color = Red;
extern color Rdy_color  = Orange;

//---- indicator buffers 



//---- buffers


string tMessage , oldmsg = "" ; 
//+--------- TRO MODIFICATION ---------------------------------------+ 
string symbol, tChartPeriod,  tShortName ;  
int    digits, period  ; 

datetime Trigger ;

int OldBars = -1 ;

color tColor = Yellow ;

//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init() 
  { 
   period       = Period() ;     
//   tChartPeriod =  TimeFrameToString(period) ;
   symbol       =  Symbol() ;
   digits       =  Digits ;   

   tShortName = "J40"+ symbol + tChartPeriod  ;

   return(0); 
  } 

int deinit() 
{ 

   
   ObjectDelete("J4031");
 
   
}  

//+------------------------------------------------------------------+ 
//| Range                                                            | 
//+------------------------------------------------------------------+ 
int start() 
  { 
  
double Stoch  ; 

double Open0, Open1, Open2, Close0, Close1, Close2, High0, High1, High2, Low0,  Low1, Low2, Range0, Range1, Range2, AvgRng3 ;
		
   Close0 = iClose(symbol,period,0) ; 
   Close1 = iClose(symbol,period,1) ;    
   Close2 = iClose(symbol,period,2) ;  
     
   Open0 = iOpen(symbol,period,0) ; 
   Open1 = iOpen(symbol,period,1) ;    
   Open2 = iOpen(symbol,period,2) ;  

   High0 = iHigh(symbol,period,0) ; 
   High1 = iHigh(symbol,period,1) ;    
   High2 = iHigh(symbol,period,2) ; 

   Low0 = iLow(symbol,period,0) ; 
   Low1 = iLow(symbol,period,1) ;    
   Low2 = iLow(symbol,period,2) ;    

  Stoch = iStochastic(symbol,period,KPeriod,DPeriod,Slowing,MAMethod,PriceField,0,0); 

color ClOpColor;


while(true)
{

if( Stoch < iStochOS && High1 < High2 &&  Low1 > Low2 ) { tMessage = Buy_Message ; ClOpColor = Buy_color ; break ; }
if( Stoch < iStochOS && High1 > High2 &&  Low1 < Low2 ) { tMessage = Buy_Message ; ClOpColor = Buy_color ; break ; }
if( Stoch > iStochOB && High1 < High2 &&  Low1 > Low2 ) { tMessage = Sell_Message ; ClOpColor = Sell_color ;  break ;  } 
if( Stoch > iStochOB && High1 > High2 &&  Low1 < Low2 ) { tMessage = Sell_Message ; ClOpColor = Sell_color ;  break ;  } 

tMessage = Wait_Message ; ClOpColor = Wait_color ; 

break;

} // while

oldmsg =  tMessage ;

//+------------------------------------------------------------------+  
                    
   ObjectCreate("J4031", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("J4031",tMessage, myFontSize , "Arial Bold", ClOpColor );
   ObjectSet("J4031", OBJPROP_CORNER, 0);
   ObjectSet("J4031", OBJPROP_XDISTANCE, price.x.offset); 
   ObjectSet("J4031", OBJPROP_YDISTANCE, price.y.offset); 


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

   WindowRedraw();    
 

//Comment("Stoch= ", DoubleToStr(Stoch,2), "\n","");

 

   return(0); 
} 

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

 