//+------------------------------------------------------------------+
//|                                                                  |                    
//|   _TRO_HL_TRADE                                                  |
//|                                                                  |
//|   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/" 
#property indicator_chart_window

//---- input parameters

extern bool my.alert.sound = false ;
extern string myWAVfile      = "siren" ;

extern int   myBars     = 4 ;

extern color LowColor  = Blue ;
extern color HighColor = Red ;

int ChartPeriod ;

   double cLow,pLow,r1,r2,r3,r4,r5,r6,OP,CL;
   int rt1,rt2,rt3,rt4,rt5,rt6, i;
   
   double MD, PM, xLow,L1,xHigh,H1,cHigh,pHigh,s1,s2,s3,s4,s5,s6, close, high, low, HH, LL;
   int D0,D1,st1,st2,st3,st4,st5,st6;
   
string  symbol, tPeriod, tAlert ;

   
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  symbol      = Symbol() ;
  ChartPeriod = Period();
  tPeriod     = TimeFrameToString( ChartPeriod ) ;
    
      ObjectCreate("TRO-L",OBJ_HLINE,0,0,0);
      ObjectSet("TRO-L",OBJPROP_COLOR,LowColor);
      ObjectSet("TRO-L",OBJPROP_STYLE,STYLE_DOT);       
      

      ObjectCreate("TRO-H",OBJ_HLINE,0,0,0);
      ObjectSet("TRO-H",OBJPROP_COLOR,HighColor);
      ObjectSet("TRO-H",OBJPROP_STYLE,STYLE_DOT); 

      ObjectCreate("TRO-LL",OBJ_HLINE,0,0,0);
      ObjectSet("TRO-LL",OBJPROP_COLOR,LowColor);
      ObjectSet("TRO-LL",OBJPROP_STYLE,STYLE_SOLID);       
      

      ObjectCreate("TRO-HH",OBJ_HLINE,0,0,0);
      ObjectSet("TRO-HH",OBJPROP_COLOR,HighColor);
      ObjectSet("TRO-HH",OBJPROP_STYLE,STYLE_SOLID); 

   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
      ObjectDelete("TRO-L");
      ObjectDelete("TRO-H");


      ObjectDelete("TRO-LL");
      ObjectDelete("TRO-HH");
      
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

//---- TODO: add your code here


 HH = -1 ;
 LL  = 999999999 ; 
 
 high = -1 ;
 low  = 999999999 ;
 
 cHigh = iHigh(NULL,ChartPeriod,0) ;
 cLow  = iLow(NULL,ChartPeriod,0) ;  
 close = iClose(NULL,ChartPeriod,0) ; 
 
 
 for( i=1; i<=myBars; i++)
 {

 xHigh = iHigh(NULL,ChartPeriod,i) ;
 xLow  = iLow(NULL,ChartPeriod,i) ;
   
 if ( xHigh < cHigh && xHigh > high) { high = xHigh ; rt1 = i ; }
 if ( xLow  > cLow  && xLow  < low ) { low  = xLow  ; st1 = i ; }  

 if ( xHigh > HH ) { HH = xHigh ; rt2 = i ; }
 if ( xLow  < LL ) { LL = xLow  ; st2 = i ; } 
  
 } // for(i=0...
  
  
if( my.alert.sound ) {
   tAlert = symbol + " " + tPeriod ;
   if(close == high ) { Alert( tAlert + " SHORT"  ) ; PlaySound(myWAVfile); }  
   else if(close == low ) { Alert( tAlert + " LONG"  ) ; PlaySound(myWAVfile); }  
}

//---- Move Object in Chart
     
ObjectMove("TRO-L",0,Time[st1],low);
ObjectMove("TRO-H",0,Time[rt1],high);

ObjectMove("TRO-LL",0,Time[st2],LL);
ObjectMove("TRO-HH",0,Time[rt2],HH);

/* 
Comment( "xHigh =", xHigh, " r1=", r1, " rt1=", rt1, "\n",
         "H1 =", H1, " r2=", r2, " rt2=", rt2, "\n",
         "cHigh=", cHigh, " pHigh=", pHigh, "\n",         
         "xLow =", xLow, " s1=", s1, " st1=", st1, "\n",
         "L1 =", L1, " s2=", s2, " st2=", st2, "\n",       
         "cLow=", cLow, " pLow=", pLow, "\n",     
         "D0 =", D0, " D1 =", D1,  "\n",              
         " ") ;
*/   
 
         
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="MN";
   }
   return(tfs);
}
 
 
//+------------------------------------------------------------------+ 