//+------------------------------------------------------------------+ 
//|    tro_3                                                         | 
//|                                                                  | 
//|   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 
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Magenta 
  

extern bool Show.Message = true ; 

extern int win = 0;
extern int price.x.offset= 0 ; 
extern int price.y.offset= 200 ; 


extern int   myFontSize = 25;

extern int myBars        = 10 ;
extern int myThreshold   = 3 ;
extern int myPipTrigger  = 4 ;

extern string Buy_Message  = "BUY ON GREEN CANDLE" ;
extern string Wait_Message = "WAIT " ;
extern string Sell_Message = "SELL ON RED CANDLE" ;
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;
 
//---- input parameters 

extern int Symbol_1_Kod=217; //140
extern int Symbol_2_Kod=218; // 141
extern int Symbol_3_Kod=142;


//---- buffers 
double FP_BuferUp[];
double FP_BuferDn[]; 
double High0, High1, High2 ;
double Low0, Low1, Low2 ;
double Diff0, Diff1, Diff2 ;
double Close0, Close1, Close2 ;
double Open0, Open1, Open2 ;

//+--------- TRO MODIFICATION ---------------------------------------+ 
string symbol, tChartPeriod,  tShortName ;  
int    digits, period  ; 

bool Trigger1,  Trigger2,  Trigger3 ;

int OldBars = -1 ;
 

color tColor = Yellow, ClOpColor ;
string tMessage , oldmsg = "", tMessageB, tMessageS ; 

//+------------------------------------------------------------------+ 
int init() 
  { 
//+--------- TRO MODIFICATION ---------------------------------------+  
   period       = Period() ;     
   tChartPeriod =  TimeFrameToString(period) ;
   symbol       =  Symbol() ;
   digits       =  Digits ;   

   tShortName = "t123"+ symbol + tChartPeriod  ;

 
   SetIndexStyle(0,DRAW_ARROW,0,1); 
   SetIndexArrow(0,Symbol_1_Kod); 
   SetIndexBuffer(0,FP_BuferUp); 
   SetIndexEmptyValue(0,0.0); 
   
   SetIndexStyle(1,DRAW_ARROW,0,1); 
   SetIndexArrow(1,Symbol_2_Kod); 
   SetIndexBuffer(1,FP_BuferDn); 
   SetIndexEmptyValue(1,0.0); 
 

   return(0); 
  } 
//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function                       | 
//+------------------------------------------------------------------+ 
int deinit() 
  { 

   ObjectDelete("TRO330");
   ObjectDelete("TRO329");
   ObjectDelete("TRO329B");
   ObjectDelete("TRO331");
   ObjectDelete("TRO332");
   ObjectDelete("TRO334");   
   
   ObjectDelete("TRO330");
   ObjectDelete("TRO329");
   ObjectDelete("TRO329B");
   ObjectDelete("TRO331");
   ObjectDelete("TRO332");
   ObjectDelete("TRO334");  

   return(0); 
  } 


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

int start() 
  { 
  
   int limit,i,counted_bars=IndicatorCounted();
//----
   limit=Bars-counted_bars;

  for(i = 0 ; i <= limit; i++) 
  { 
    High0 = iHigh(NULL,period,i) ;
    Low0  = iLow(NULL,period,i) ;
    Diff0 = iClose(NULL,period,i) - iOpen(NULL,period,i) ;
    Diff1 = iClose(NULL,period,i+1) - iOpen(NULL,period,i+1) ;  
    Diff2 = iClose(NULL,period,i+2) - iOpen(NULL,period,i+2) ;
        
    if( Diff0 < 0 && Diff1 < 0 && Diff2 < 0  ) {FP_BuferUp[i] = Low0 ; } else  {FP_BuferUp[i] = 0 ; }
    if( Diff0 >= 0 && Diff1 >= 0 && Diff2 >= 0  ) {FP_BuferDn[i] = High0 ; } else  {FP_BuferDn[i] = 0 ; }
      
  } 
   
   
   tMessageB = "" ;
   tMessageS = "" ;
      
   Close0 = iClose(NULL,period,0) ;
   Close1 = iClose(NULL,period,1) ;
   Open0  = iOpen(NULL,period,0) ;
   Open1  = iOpen(NULL,period,1) ;
   
   if( Open0 < Close1 ) { tMessageB = "!!" ;  }  
   if( Open0 > Close1 ) { tMessageS = "!!" ;  }  
      
   while(true)
   { 
      if(FP_BuferUp[1] != 0) { ClOpColor = Buy_color ;  tMessage = Buy_Message  + tMessageB ; break ; }           
      if(FP_BuferDn[1] != 0) { ClOpColor = Sell_color ; tMessage = Sell_Message + tMessageS ; break ; }    
      
      ClOpColor = Wait_color ; tMessage = Wait_Message ;  break ;
   }

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


//+------------------------------------------------------------------+     
   
               
   return(0);
}

//+--------- TRO MODIFICATION ---------------------------------------+  

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);
}


/*

Comment( 
"high0 = ", DoubleToStr(high0 , digits), "\n",        
"high1 = ", DoubleToStr(high1 , digits), "\n",  
"high2 = ", DoubleToStr(high2 , digits), "\n",  
"Low0 = ", DoubleToStr(Low0 , digits), "\n",        
"Low1 = ", DoubleToStr(Low1 , digits), "\n",  
"Low2 = ", DoubleToStr(Low2 , digits), "\n",  
"") ; 

*/