//+------------------------------------------------------------------+
//|   TRO_SupResHHLL                                                 |
//|                                                                  | 
//|   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 Show.Labels = true ;
extern bool Show.Gauge  = true ;

extern double    myUpper      = 0 ; 
extern double    myLower      = 0 ;
extern double    myWindow     = 0.77 ;
extern int       myBars       = 3 ;
extern int       myShift      = 1 ;

extern int myChartY = 200 ;
extern bool Horizontal = true ;


extern int myPctHi = 66 ;
extern int myPctLo = 34 ;

extern color myPctHiColor = Red ; 
extern color myPctMidColor = DimGray ; 
extern color myPctLoColor = Blue ; 

extern int myHighMark = 225 ; // 218 = dn arrowhead, 242 = dn arrow, 226, 233 dn arrow solid, 201, 202 dn arrow twist 
extern int myLowMark  = 225 ; // 217 = up arrowhead, 241 = up arrow, 225, 233 up arrow solid, 199, 200 up arrow twist 
extern int myBackMark = 225 ;


extern color ColorHeading = DimGray;
extern color ColorUpper = Red ;
extern color ColorShort = Crimson ;
extern color ColorLong  = Green ;
extern color ColorLower = Blue ;

//---- buffers


int i;
  
double R1, R2, R3 ;  

double X05 ;
double X06 ;   
double X07 ;
double X08, XRN ; 
double xRet ;
double xRetPct;    
  
string tChartPeriod ; 

string tLabel01, tLabel02, tLabel03, tLabel04, tLabel05, tLabel06, tLabel07  ;   
string tRes0 = "hhRes_0" ;
string tSup0 = "hhSup_0" ;
string tFib1 = "hhFib1_0" ;
string tFib2 = "hhFib2_0" ;

double range , point ;
double DynR; 
double DynS;  
datetime StartTime;
int digits ;

double Entry, work, goShort, goLong, reward, risk, ratio, Pct  ;

bool xAutoCalc = false;
int nHH, nLL; 
string tPIVOT0 ="fgres" ;
string tPIVOT1 ="fgsup" ; 
string tPIVOT2 ="fgslo" ;
string shortName, OBJ001, OBJ002,OBJ003,OBJ004,OBJ005,OBJ006,OBJ007,OBJ008,OBJ009;
string OBJ010, OBJ011, OBJ012,OBJ013,OBJ014,OBJ015,OBJ016,OBJ017,OBJ018,OBJ019;
string OBJ020, OBJ021, OBJ022,OBJ023,OBJ024,OBJ025,OBJ026,OBJ027,OBJ028,OBJ029;

color colorPct ;

//+------------------------------------------------------------------+
   
int init()
  {

  shortName  = MakeUniqueName("srhl ","") + myBars ;
  tChartPeriod =  TimeFrameToString(Period()) ;
  IndicatorShortName(shortName);
  
  tLabel01 = "1Resistance" + tChartPeriod ;
  tLabel02 = "2Support" + tChartPeriod ;
  tLabel03 = "3Short" + tChartPeriod ; 
  tLabel04 = "4Long" + tChartPeriod ;

   tRes0 = shortName + "Res_0" ;
   tSup0 = shortName + "Sup_0" ;
   tFib1 = shortName + "Fib1_0" ;
   tFib2 = shortName + "Fib2_0" ;

 tPIVOT0 = shortName + "fgres" ;
 tPIVOT1 = shortName + "fgsup" ; 
 tPIVOT2 = shortName + "fgslo" ;


  OBJ001 = shortName + "001" ;
  OBJ002 = shortName + "002" ;
  OBJ003 = shortName + "003" ;
  OBJ004 = shortName + "004" ;
  OBJ005 = shortName + "005" ;
  OBJ006 = shortName + "006" ;
  OBJ007 = shortName + "007" ;
  OBJ008 = shortName + "008" ;
  OBJ009 = shortName + "009" ;
  OBJ010 = shortName + "010" ;
  OBJ011 = shortName + "0011" ;
  OBJ012 = shortName + "0012" ;
  OBJ013 = shortName + "0013" ;
  OBJ014 = shortName + "0014" ;
  OBJ015 = shortName + "0015" ;
  OBJ016 = shortName + "0016" ;
  OBJ017 = shortName + "0017" ;
  OBJ018 = shortName + "0018" ;
  OBJ019 = shortName + "0019" ;
  OBJ020 = shortName + "0020" ;
  OBJ021 = shortName + "0021" ;
  OBJ022 = shortName + "0022" ;
  OBJ023 = shortName + "0023" ;
  OBJ024 = shortName + "0024" ;  
  
  digits = Digits ;
  point  = Point ;   
  
  if( myUpper == 0 ) { xAutoCalc = true ; }   
      
 work    = ( myUpper  - myLower ) * myWindow  ; 
   
 goShort = myLower  + work   ;
 goLong  = myUpper  - work   ;
 

 reward   = myUpper - goLong ;
 risk     = goLong - myLower ;
 ratio    = reward / risk ;
 range    = ( myUpper  - myLower ) / point ;

   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectsDeleteAll( 0, OBJ_FIBO ) ;
   ObjectDelete(tPIVOT0);
   ObjectDelete(tPIVOT1); 
   ObjectDelete(tPIVOT2);      
   ObjectDelete(OBJ001);
   ObjectDelete(OBJ002);
   ObjectDelete(OBJ003);
   ObjectDelete(OBJ004);  
   ObjectDelete(OBJ005); 
   ObjectDelete(OBJ006);
   ObjectDelete(OBJ007);
   ObjectDelete(OBJ008);
   ObjectDelete(OBJ009);
   ObjectDelete(OBJ010);
   ObjectDelete( OBJ021 );
   ObjectDelete(  OBJ020 );   
   ObjectDelete(  OBJ019 );
   ObjectDelete(  OBJ018 );
   ObjectDelete(  OBJ017 );
   ObjectDelete(  OBJ016 );
   ObjectDelete(  OBJ015 );
   ObjectDelete( OBJ011 );
   ObjectDelete(OBJ013);      
   ObjectDelete(OBJ013);           
   ObjectDelete(OBJ014); 
   ObjectDelete(OBJ022);  
   ObjectDelete(OBJ023);           
   ObjectDelete(OBJ024);
   ObjectDelete(tRes0);           
   ObjectDelete(tSup0);

       
   return(0);
  }

int start()
{

if( xAutoCalc == true ) DoWork() ;  

if( Show.Labels) DoShowLabels() ;

if( Show.Gauge ) DoShowGauge() ;

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

void DoWork()
{
  
/*   
Reward = Target Point - Entry Point = 1.9869-1.9782 = 87 pips

Risk= Entry Point - Stop Loss = 1.9782 - 1.9747 = 35pips

Risk to Reward Ratio = 87 / 35 = 1:2.5

*/
 
 nHH      =  Highest(NULL,0,MODE_HIGH,myBars,myShift); 
 nLL      =  Lowest(NULL,0,MODE_LOW,myBars,myShift); 
 
 myUpper      = High[nHH]; 
 myLower      = Low[nLL]; 

      
 work     = ( myUpper  - myLower ) * myWindow  ; 
   
 goShort  = myLower  + work   ;
 goLong   = myUpper  - work   ;
 
 reward   = myUpper - goLong ;
 risk     = goLong - myLower ;
 ratio    = reward / risk ;
 range    = (myUpper - myLower)  ; 
  
   if( range != 0) { Pct = 100 * ( Close[0]  - myLower ) / range ; } else {Pct = 0 ;} 

   if(Pct > myPctHi ) { colorPct = myPctHiColor ; } else  
   if(Pct < myPctLo ) { colorPct = myPctLoColor ; } else { colorPct = myPctMidColor ; }


  if (ObjectFind(tPIVOT0) != 0)
      {
          ObjectCreate(tPIVOT0,OBJ_ARROW,0,Time[nHH],myLower);
          ObjectSet(tPIVOT0,OBJPROP_ARROWCODE,myHighMark);
//          ObjectSet(tPIVOT0,OBJPROP_WIDTH,myBoxWidth);  
          ObjectSet(tPIVOT0,OBJPROP_COLOR,ColorUpper);  
      } 
      else
      {
         ObjectMove(tPIVOT0,0,Time[nHH],myLower);
      }

 
  if (ObjectFind(tPIVOT1) != 0)
      {
          ObjectCreate(tPIVOT1,OBJ_ARROW,0,Time[myBars],myLower);
          ObjectSet(tPIVOT1,OBJPROP_ARROWCODE,myBackMark);
//          ObjectSet(tPIVOT1,OBJPROP_WIDTH,myBoxWidth);  
          ObjectSet(tPIVOT1,OBJPROP_COLOR,ColorHeading);  
      } 
      else
      {
         ObjectMove(tPIVOT1,0,Time[myBars],myLower);
      }

  if (ObjectFind(tPIVOT2) != 0)
      {
          ObjectCreate(tPIVOT2,OBJ_ARROW,0,Time[nLL],myLower);
          ObjectSet(tPIVOT2,OBJPROP_ARROWCODE,myLowMark);
//          ObjectSet(tPIVOT2,OBJPROP_WIDTH,myBoxWidth);  
          ObjectSet(tPIVOT2,OBJPROP_COLOR,ColorLower);  
      } 
      else
      {
         ObjectMove(tPIVOT2,0,Time[nLL],myLower);
      }


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

 
void DoShowGauge()
{

string StrX05 = "+Fib618" ; 
string StrX06 = "+Fib382" ; 
string StrX07 = "-Fib382" ; 
string StrX08 = "-Fib618" ;  
string StrXRN = "Range" ;  
  
        
	
	int Precision, dig;	

   dig = Digits ;

 
int sPeriod= Period();
     	
//---- Set Pivots labels

   int WindowToUse;
   int Corner_line, Xdist_line;
   int Corner_text, Corner_vHHLLFP, Xdist_text, Xdist_vHHLLFP;
   int Ydist_line5;
   int Corner_pivots, Xdist_pivots, Ydist_pivots;
   int Ydist_R3, Ydist_R2, Ydist_R1, Ydist_PV, Ydist_S1, Ydist_S2, Ydist_S3, Ydist_X05, Ydist_X06, Ydist_X07, Ydist_X08, Ydist_X09,Ydist_XRN ;
  
   int YdistInc ;
    WindowToUse =  0;
    Corner_line = 1;
    Corner_text = 1; Corner_vHHLLFP = 1;
    Xdist_line = 21; Xdist_text = 93; Xdist_vHHLLFP = 23;
    Corner_pivots = 1; Xdist_pivots = 21; 
    Ydist_pivots = myChartY;  
    Ydist_line5 = Ydist_pivots + 11; YdistInc = 15 ;
    Ydist_R3 = Ydist_pivots + 25; 
    Ydist_R2 = Ydist_R3 + YdistInc; 
    Ydist_R1 = Ydist_R3 + YdistInc*2; 
    Ydist_PV = Ydist_R3 + YdistInc*3; 
    Ydist_X05 = Ydist_R3 + YdistInc*4;
    Ydist_X06 = Ydist_R3 + YdistInc*5;    
    Ydist_X07 = Ydist_R3 + YdistInc*6;
    Ydist_X08 = Ydist_R3 + YdistInc*7;    
    Ydist_X09 = Ydist_R3 + YdistInc*8;    

 


      
   ObjectCreate(OBJ001, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ001, tChartPeriod + " SupResHHLL("+myBars+")."+myShift,9, "Verdana", ColorHeading);
   ObjectSet(OBJ001, OBJPROP_CORNER, Corner_pivots);
   ObjectSet(OBJ001, OBJPROP_XDISTANCE, Xdist_pivots);
   ObjectSet(OBJ001, OBJPROP_YDISTANCE, Ydist_pivots);
   
   ObjectCreate(OBJ002, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ002,"-----------------------------",7, "Verdana", ColorHeading);
   ObjectSet(OBJ002, OBJPROP_CORNER, Corner_line);
   ObjectSet(OBJ002, OBJPROP_XDISTANCE, Xdist_line);
   ObjectSet(OBJ002, OBJPROP_YDISTANCE, Ydist_line5);
   
   ObjectCreate(OBJ003, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ003,"Resistance",9, "Verdana", ColorUpper);
   ObjectSet(OBJ003, OBJPROP_CORNER, Corner_text);
   ObjectSet(OBJ003, OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet(OBJ003, OBJPROP_YDISTANCE, Ydist_R3);

   ObjectCreate(OBJ004, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ004," "+DoubleToStr(myUpper,dig),9, "Verdana", ColorUpper);
   ObjectSet(OBJ004, OBJPROP_CORNER, Corner_vHHLLFP);
   ObjectSet(OBJ004, OBJPROP_XDISTANCE, Xdist_vHHLLFP);
   ObjectSet(OBJ004, OBJPROP_YDISTANCE, Ydist_R3);
   
   ObjectCreate(OBJ005, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ005,"Go Short",9, "Verdana", ColorShort);
   ObjectSet(OBJ005, OBJPROP_CORNER, Corner_text);
   ObjectSet(OBJ005, OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet(OBJ005, OBJPROP_YDISTANCE, Ydist_R2);
   
   ObjectCreate(OBJ006, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ006," "+DoubleToStr(goShort,dig),9, "Verdana", ColorShort);
   ObjectSet(OBJ006, OBJPROP_CORNER, Corner_vHHLLFP);
   ObjectSet(OBJ006, OBJPROP_XDISTANCE, Xdist_vHHLLFP);
   ObjectSet(OBJ006, OBJPROP_YDISTANCE, Ydist_R2);
   

   ObjectCreate(OBJ007, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ007,"Go Long",9, "Verdana", ColorLong );
   ObjectSet(OBJ007, OBJPROP_CORNER, Corner_text);
   ObjectSet(OBJ007, OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet(OBJ007, OBJPROP_YDISTANCE, Ydist_R1);
   
   ObjectCreate(OBJ008, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ008," "+DoubleToStr(goLong,dig),9, "Verdana", ColorLong);
   ObjectSet(OBJ008, OBJPROP_CORNER, Corner_vHHLLFP);
   ObjectSet(OBJ008, OBJPROP_XDISTANCE, Xdist_vHHLLFP);
   ObjectSet(OBJ008, OBJPROP_YDISTANCE, Ydist_R1);
   
   ObjectCreate(OBJ009, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ009,"Support",9, "Verdana", ColorLower);
   ObjectSet(OBJ009, OBJPROP_CORNER, Corner_text);
   ObjectSet(OBJ009, OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet(OBJ009, OBJPROP_YDISTANCE, Ydist_PV);
   
   ObjectCreate(OBJ010, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ010," "+DoubleToStr(myLower,dig),9, "Verdana", ColorLower);
   ObjectSet(OBJ010, OBJPROP_CORNER, Corner_vHHLLFP);
   ObjectSet(OBJ010, OBJPROP_XDISTANCE, Xdist_vHHLLFP);
   ObjectSet(OBJ010, OBJPROP_YDISTANCE, Ydist_PV);   
 

   ObjectCreate(OBJ011, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ011,"RISK ",9, "Verdana", ColorHeading );
   ObjectSet(OBJ011, OBJPROP_CORNER, Corner_text);
   ObjectSet(OBJ011, OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet(OBJ011, OBJPROP_YDISTANCE, Ydist_X05);
   
   ObjectCreate(OBJ015, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ015," "+DoubleToStr(risk/Point,0),9, "Verdana", ColorHeading);
   ObjectSet(OBJ015, OBJPROP_CORNER, Corner_vHHLLFP);
   ObjectSet(OBJ015, OBJPROP_XDISTANCE, Xdist_vHHLLFP);
   ObjectSet(OBJ015, OBJPROP_YDISTANCE, Ydist_X05);
    
   ObjectCreate(OBJ016, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ016,"REWARD",9, "Verdana", ColorHeading );
   ObjectSet(OBJ016, OBJPROP_CORNER, Corner_text);
   ObjectSet(OBJ016, OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet(OBJ016, OBJPROP_YDISTANCE, Ydist_X06);
   
   ObjectCreate(OBJ017, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ017," "+DoubleToStr(reward/Point,0),9, "Verdana", ColorHeading);
   ObjectSet(OBJ017, OBJPROP_CORNER, Corner_vHHLLFP);
   ObjectSet(OBJ017, OBJPROP_XDISTANCE, Xdist_vHHLLFP);
   ObjectSet(OBJ017, OBJPROP_YDISTANCE, Ydist_X06);

   ObjectCreate(OBJ018, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ018,"RATIO",9, "Verdana", ColorHeading );
   ObjectSet(OBJ018, OBJPROP_CORNER, Corner_text);
   ObjectSet(OBJ018, OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet(OBJ018, OBJPROP_YDISTANCE, Ydist_X07);
   
   ObjectCreate(OBJ019, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ019," "+DoubleToStr(ratio,dig),9, "Verdana", ColorHeading);
   ObjectSet(OBJ019, OBJPROP_CORNER, Corner_vHHLLFP);
   ObjectSet(OBJ019, OBJPROP_XDISTANCE, Xdist_vHHLLFP);
   ObjectSet(OBJ019, OBJPROP_YDISTANCE, Ydist_X07);

   ObjectCreate(OBJ020, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ020,"RANGE",9, "Verdana", ColorHeading );
   ObjectSet(OBJ020, OBJPROP_CORNER, Corner_text);
   ObjectSet(OBJ020, OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet(OBJ020, OBJPROP_YDISTANCE, Ydist_X08);
   
   ObjectCreate(OBJ021, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ021," "+DoubleToStr(range / point ,0),9, "Verdana", ColorHeading);
   ObjectSet(OBJ021, OBJPROP_CORNER, Corner_vHHLLFP);
   ObjectSet(OBJ021, OBJPROP_XDISTANCE, Xdist_vHHLLFP);
   ObjectSet(OBJ021, OBJPROP_YDISTANCE, Ydist_X08);


   ObjectCreate(OBJ022, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ022,"% in Range",9, "Verdana", ColorHeading );
   ObjectSet(OBJ022, OBJPROP_CORNER, Corner_text);
   ObjectSet(OBJ022, OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet(OBJ022, OBJPROP_YDISTANCE, Ydist_X09);
   
   ObjectCreate(OBJ023, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ023, DoubleToStr(Pct,0) + "%" ,9, "Verdana", colorPct);
   ObjectSet(OBJ023, OBJPROP_CORNER, Corner_vHHLLFP);
   ObjectSet(OBJ023, OBJPROP_XDISTANCE, Xdist_vHHLLFP);
   ObjectSet(OBJ023, OBJPROP_YDISTANCE, Ydist_X09);

} 

void DoShowLabels()
{
   range = myUpper  - myLower  ;
	if(ObjectFind(tRes0) == -1)
		ObjectCreate(tRes0,OBJ_FIBO,0,StartTime,myUpper+range,StartTime,myUpper);
	else
	{
		ObjectSet(tRes0,OBJPROP_TIME2, StartTime);
		ObjectSet(tRes0,OBJPROP_TIME1, StartTime);
		ObjectSet(tRes0,OBJPROP_PRICE1,myUpper+range);
		ObjectSet(tRes0,OBJPROP_PRICE2,myUpper);
	}
   ObjectSet(tRes0,OBJPROP_LEVELCOLOR,ColorUpper);
   ObjectSet(tRes0,OBJPROP_FIBOLEVELS,1);
   ObjectSet(tRes0,OBJPROP_FIRSTLEVEL+0,0.0);	
   ObjectSetFiboDescription(tRes0,0, DoubleToStr(myUpper,digits)+ " Resistance  "); 
   ObjectSet(tRes0,OBJPROP_RAY,true);
   ObjectSet(tRes0,OBJPROP_BACK,true);


		if(ObjectFind(tSup0) == -1)
			ObjectCreate(tSup0,OBJ_FIBO,0,StartTime,myLower-range,StartTime+PERIOD_H4*60,myLower);
		else
		{
			ObjectSet(tSup0,OBJPROP_TIME2, StartTime);
			ObjectSet(tSup0,OBJPROP_TIME1, StartTime);
			ObjectSet(tSup0,OBJPROP_PRICE1,myUpper);
			ObjectSet(tSup0,OBJPROP_PRICE2,myLower);
		}
   	ObjectSet(tSup0,OBJPROP_LEVELCOLOR,ColorLower); 
   	ObjectSet(tSup0,OBJPROP_FIBOLEVELS,1);
   
   	ObjectSet(tSup0,OBJPROP_FIRSTLEVEL+0,0.000);	
   	ObjectSetFiboDescription(tSup0,0,DoubleToStr(myLower,digits)+ " Support  "); 

   	ObjectSet(tSup0,OBJPROP_RAY,true);
   	ObjectSet(tSup0,OBJPROP_BACK,true);

   
		if(ObjectFind(tFib1) == -1)
			ObjectCreate(tFib1,OBJ_FIBO,0,StartTime,myUpper,StartTime+PERIOD_H4*60,myLower);
		else
		{
			ObjectSet(tFib1,OBJPROP_TIME2, StartTime);
			ObjectSet(tFib1,OBJPROP_TIME1, StartTime);
			ObjectSet(tFib1,OBJPROP_PRICE1,myUpper);
			ObjectSet(tFib1,OBJPROP_PRICE2,myLower);
		}
   	ObjectSet(tFib1,OBJPROP_LEVELCOLOR,ColorShort); 
   	ObjectSet(tFib1,OBJPROP_FIBOLEVELS,1);
   
   	ObjectSet(tFib1,OBJPROP_FIRSTLEVEL+0,myWindow);	
   	ObjectSetFiboDescription(tFib1,0,DoubleToStr(goShort,digits)+ " go Short  "); 

   	ObjectSet(tFib1,OBJPROP_RAY,true);
   	ObjectSet(tFib1,OBJPROP_BACK,true);
  
   
		if(ObjectFind(tFib2) == -1)
			ObjectCreate(tFib2,OBJ_FIBO,0,StartTime,myUpper,StartTime+PERIOD_H4*60,myLower);
		else
		{
			ObjectSet(tFib2,OBJPROP_TIME2, StartTime);
			ObjectSet(tFib2,OBJPROP_TIME1, StartTime);
			ObjectSet(tFib2,OBJPROP_PRICE1,myUpper);
			ObjectSet(tFib2,OBJPROP_PRICE2,myLower);
		}
   	ObjectSet(tFib2,OBJPROP_LEVELCOLOR,ColorLong); 
   	ObjectSet(tFib2,OBJPROP_FIBOLEVELS,2);
   
   	ObjectSet(tFib2,OBJPROP_FIRSTLEVEL+0,1-myWindow);	
   	ObjectSetFiboDescription(tFib2,0,DoubleToStr(goLong,digits)+ " go Long  "); 

   	ObjectSet(tFib2,OBJPROP_RAY,true);
   	ObjectSet(tFib2,OBJPROP_BACK,true);



      
}

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

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);
}
//+------------------------------------------------------------------+
 
string MakeUniqueName(string first, string rest)
{
   string result = first+(MathRand()%1001)+rest;

   while (WindowFind(result)> 0)
          result = first+(MathRand()%1001)+rest;
   return(result);
}
//+------------------------------------------------------------------+ 

/*
Comment(
"myUpper = ", DoubleToStr( myUpper, Digits), "\n",
"myLower = ", DoubleToStr( myLower, Digits), "\n",
"reward = ", DoubleToStr( reward, Digits), "\n",
"risk = ", DoubleToStr( risk, Digits), "\n",
"ratio = ", DoubleToStr( ratio, Digits), "\n",

"") ;

   ObjectCreate(OBJ020, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ020,"WINDOW",9, "Verdana", ColorHeading );
   ObjectSet(OBJ020, OBJPROP_CORNER, Corner_text);
   ObjectSet(OBJ020, OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet(OBJ020, OBJPROP_YDISTANCE, Ydist_X08);
   
   ObjectCreate(OBJ021, OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText(OBJ021," "+DoubleToStr(myWindow,2),9, "Verdana", ColorHeading);
   ObjectSet(OBJ021, OBJPROP_CORNER, Corner_vHHLLFP);
   ObjectSet(OBJ021, OBJPROP_XDISTANCE, Xdist_vHHLLFP);
   ObjectSet(OBJ021, OBJPROP_YDISTANCE, Ydist_X08);

*/