//+------------------------------------------------------------------+ 
//|    _TRO_BuyZone_Original_Targets_Alerts                          | 
//|                                                                  | 
//|   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.therumpldone.com/" 



#property indicator_chart_window
//---- input parameters                  price.x.offset  price.y.offset

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


extern bool show.info        = true;
extern bool show.trigger     = true;

extern bool sound.trigger    = true;


extern int    myStyle        = STYLE_DOT;
extern color  myTargetColor  = DarkGreen ;
extern color  tAlertColor    = Yellow ;
extern double myProfitTarget = 6 ;
extern double myStopLoss     = 7 ;


extern string    session_name = "";
extern color     session_color = White;
//extern int       open_time=8;
extern int       straddle_width=3;
extern int       channel=1;
extern color myColor = DarkGray ;

double open_price;
double rates_h1[2][6];
string OP, BZ, BZW, SZ, SZW, LTGT, STGT;



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators


  OP = "Open " + session_name;
  BZ = "Buy zone " + session_name;
  BZW = "Buy zone width " + session_name;
  SZ = "Sell zone " + session_name;
  SZW = "Sell zone width " + session_name;
  LTGT = "Long Target"   + session_name;
  STGT = "Short Target " + session_name;

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete(OP);
   ObjectDelete(BZ);
   ObjectDelete(BZW);
   
   ObjectDelete(SZ);
   ObjectDelete(SZW);
   ObjectDelete(LTGT);
   ObjectDelete(STGT);
      
   ObjectDelete(session_name);

   ObjectDelete("BZ_630");
   ObjectDelete("BZ_629");
   ObjectDelete("BZ_629B");
   ObjectDelete("BZ_631");
   ObjectDelete("BZ_632");
   ObjectDelete("BZ_634");

   
      
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----


   if( TimeHour(Time[0]) != TimeHour(Time[1]) ) 
     { 
        // draw the vertical bars that marks the time span
   double level= (High[1] + Low[1] + Close[1]) / 3;
   SetTimeLine("HourStart", "Hour", 0, White, level+10*Point);
     }
   
   
open_price = iOpen(NULL,PERIOD_H1,0);  


double LgTop = open_price +( straddle_width+channel)*Point ;	
double LgBot = open_price + straddle_width*Point ;

double ShTop = open_price - straddle_width*Point ;	
double ShBot = open_price - (straddle_width+channel)*Point ; 


double LgProfit = ( iHigh(NULL,PERIOD_H1,0) -  LgTop ) / Point  ;
double ShProfit = ( ShBot - iLow(NULL,PERIOD_H1,0) )   / Point  ;

double LgTarget =  LgTop + myProfitTarget*Point ;
double ShTarget =  ShBot - myProfitTarget*Point ;

double LgStop   =  LgTop - myStopLoss*Point ;
double ShStop   =  ShBot + myStopLoss*Point ;

    if (ObjectFind(OP) != 0)
     
      {
      
      
          ObjectCreate(session_name,OBJ_TEXT,0,CurTime(),open_price+4*Point);
          ObjectSetText(session_name, session_name+"                                                                                                                                                        ",
                                                                                  8, "Arial",session_color);
      //    ObjectSet(session_name, OBJPROP_YDISTANCE, 100);
          
          
          ObjectCreate(OP, OBJ_HLINE, 0, CurTime(), open_price);
          ObjectSet(OP, OBJPROP_STYLE, STYLE_DOT);
          ObjectSet(OP, OBJPROP_COLOR, session_color);
          
          ObjectCreate(BZ, OBJ_HLINE, 0, CurTime(), LgBot );
          ObjectSet(BZ, OBJPROP_STYLE, STYLE_DASH);
          ObjectSet(BZ, OBJPROP_COLOR, Blue);
          
          ObjectCreate(BZW, OBJ_HLINE, 0, CurTime(), LgTop );
          ObjectSet(BZW, OBJPROP_STYLE, STYLE_DASH);
          ObjectSet(BZW, OBJPROP_COLOR, Blue);
          
          
          ObjectCreate(SZ, OBJ_HLINE, 0, CurTime(), ShTop);
          ObjectSet(SZ, OBJPROP_STYLE, STYLE_DASH);
          ObjectSet(SZ, OBJPROP_COLOR, Red);
          
          ObjectCreate(SZW, OBJ_HLINE, 0, CurTime(), ShBot);
          ObjectSet(SZW, OBJPROP_STYLE, STYLE_DASH);
          ObjectSet(SZW, OBJPROP_COLOR, Red);
          
          ObjectCreate(LTGT, OBJ_HLINE, 0, CurTime(), LgTarget );
          ObjectSet(LTGT, OBJPROP_STYLE, myStyle);
          ObjectSet(LTGT, OBJPROP_COLOR, myTargetColor );   
          
          ObjectCreate(STGT, OBJ_HLINE, 0, CurTime(), ShTarget );
          ObjectSet(STGT, OBJPROP_STYLE, myStyle);
          ObjectSet(STGT, OBJPROP_COLOR, myTargetColor );           
      
       
      }
      
      else
      {
         ObjectMove(session_name,0,CurTime(),open_price+4*Point);
         ObjectMove(OP,   0, CurTime(), open_price);
         ObjectMove(BZ,   0, CurTime(), LgBot);
         ObjectMove(BZW,  0, CurTime(), LgTop); 
         ObjectMove(SZ,   0, CurTime(), ShTop);
         ObjectMove(SZW,  0, CurTime(), ShBot);
         ObjectMove(LTGT, 0, CurTime(), LgTarget );         
         ObjectMove(STGT, 0, CurTime(), ShTarget );      
      }


string tAlert = "BUY ZONE" ;
tAlertColor = Yellow ;

//+------------------------------------------------------------------+ 
if ( show.trigger) {    



bool LgTrigger = false ;
bool ShTrigger = false ;

double close = Close[0] ;
double diff  = close - Open[0] ;

if ( close > LgTarget ) { tAlert = "GREEDY" ;  tAlertColor = Red ; DoSoundAlert( "GREEDY" ); } else 
if ( close == LgTarget ) { tAlert = "    SELL" ;  tAlertColor = Red ; DoSoundAlert( "SELL" ); } else 
if ( close > LgTop )  { LgTrigger = true ; tAlert = "    LONG" ;  tAlertColor = LimeGreen ; } else 
if ( (close == LgTop ) && ( LgProfit < 0 ) ) { LgTrigger = true ; tAlert = "    BUY" ;   tAlertColor = Lime ; DoSoundAlert( "BUY" ); } else 
if ( (LgTrigger == true ) && ( close <=  LgStop ) ) 
   { tAlert = "SL SELL" ;   tAlertColor = Red ; } 


if ( close <  ShTarget  ) { tAlert = "GREEDY" ;  tAlertColor = Lime ; DoSoundAlert( "GREEDY" );} else 
if ( close == ShTarget  ) { tAlert = "   COVER" ;  tAlertColor = Lime ; DoSoundAlert( "COVER" );} else 
if ( close < ShBot )  { ShTrigger = true ; tAlert = "   SHORT" ;  tAlertColor = OrangeRed  ; } else 
if ( ( close == ShBot  ) && ( ShProfit < 0 ) ) {ShTrigger = true ; tAlert = "SELL SHORT" ;   tAlertColor = Red ; DoSoundAlert( "SELL SHORT" );} else 
if ( (ShTrigger == true ) && ( close >=  ShStop ) ) 
   { tAlert = "SL COVER" ;   tAlertColor = Lime ; } 
    
   

/*
                     
   ObjectCreate("BZ_ALERT", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("BZ_ALERT",tAlert, 30, "Arial Bold", tAlertColor );
   ObjectSet("BZ_ALERT", OBJPROP_CORNER, 0);
   ObjectSet("BZ_ALERT", OBJPROP_XDISTANCE, 400+price.x.offset); // 765
   ObjectSet("BZ_ALERT", OBJPROP_YDISTANCE, 215+price.y.offset); // 210
           
*/    
    

//+------------------------------------------------------------------+  
//  WindowRedraw();    
} // if show.trigger   
   
//+------------------------------------------------------------------+ 
if (show.info) {    

if ( show.trigger == false ) {  tAlertColor = Gray ; }

   ObjectCreate("BZ_630", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("BZ_630", tAlert , 30, "Arial Bold", tAlertColor );
   ObjectSet("BZ_630", OBJPROP_CORNER, 0);
   ObjectSet("BZ_630", OBJPROP_XDISTANCE, 725+price.x.offset); // 760
   ObjectSet("BZ_630", OBJPROP_YDISTANCE, 160+price.y.offset);
 
   ObjectCreate("BZ_629", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("BZ_629",DoubleToStr(LgTop,Digits), 15, "Arial Bold", Blue);
   ObjectSet("BZ_629", OBJPROP_CORNER, 0);
   ObjectSet("BZ_629", OBJPROP_XDISTANCE, 770+price.x.offset);
   ObjectSet("BZ_629", OBJPROP_YDISTANCE, 197+price.y.offset);
   
   ObjectCreate("BZ_629b", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("BZ_629b",DoubleToStr( ShBot ,Digits), 15, "Arial Bold", Red);
   ObjectSet("BZ_69b", OBJPROP_CORNER, 0);
   ObjectSet("BZ_629b", OBJPROP_XDISTANCE, 770+price.x.offset);
   ObjectSet("BZ_629b", OBJPROP_YDISTANCE, 260+price.y.offset);                 
                     
   ObjectCreate("BZ_631", OBJ_LABEL, win, 0, 0);//HiLow LABEL
   ObjectSetText("BZ_631",DoubleToStr(open_price,Digits), 30, "Arial Bold", White );
   ObjectSet("BZ_631", OBJPROP_CORNER, 0);
   ObjectSet("BZ_631", OBJPROP_XDISTANCE, 765+price.x.offset); // 765
   ObjectSet("BZ_631", OBJPROP_YDISTANCE, 215+price.y.offset); // 210
           
 
   ObjectCreate("BZ_632", OBJ_LABEL, win, 0, 0);
   ObjectSetText("BZ_632",DoubleToStr( LgProfit ,0), 15, "Arial Bold", LimeGreen);
   ObjectSet("BZ_632", OBJPROP_CORNER, 0);
   ObjectSet("BZ_632", OBJPROP_XDISTANCE, 860+price.x.offset);
   ObjectSet("BZ_632", OBJPROP_YDISTANCE, 197+price.y.offset);
                 
   ObjectCreate("BZ_634", OBJ_LABEL, win, 0, 0);
   ObjectSetText("BZ_634",DoubleToStr( ShProfit ,0), 15, "Arial Bold", Crimson);
   ObjectSet("BZ_634", OBJPROP_CORNER, 0);
   ObjectSet("BZ_634", OBJPROP_XDISTANCE, 860+price.x.offset);
   ObjectSet("BZ_634", OBJPROP_YDISTANCE, 260+price.y.offset);    
    

//+------------------------------------------------------------------+  
   WindowRedraw();    
} // if showinfo
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
void DoSoundAlert( string vAlert ) 
{

  if (sound.trigger) {
         Print(vAlert, "  ", Symbol(), "  ", DoubleToStr(Close[0],Digits) );
         Alert(vAlert, "  ", Symbol(), "  ", DoubleToStr(Close[0],Digits) );
  }
}

//+------------------------------------------------------------------+
//| Helper                                                           |
//+------------------------------------------------------------------+
void SetTimeLine(string objname, string text, int idx, color col1, double vleveltext) 
{
   string name= "[PIVOT] " + objname;
   int x= Time[idx];

   if (ObjectFind(name) != 0) 
      ObjectCreate(name, OBJ_TREND, 0, x, 0, x, 100);
   else {
      ObjectMove(name, 0, x, 0);
      ObjectMove(name, 1, x, 100);
   }
   
   ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
   ObjectSet(name, OBJPROP_COLOR, myColor);
   
   if (ObjectFind(name + " Label") != 0) 
      ObjectCreate(name + " Label", OBJ_TEXT, 0, x, vleveltext);
   else
      ObjectMove(name + " Label", 0, x, vleveltext);
            
   ObjectSetText(name + " Label", text, 8, "Arial", col1);
}