//+------------------------------------------------------------------+
// _TRO_SR_FIB_PROJ - MODIFIED BY AVERY T. HORTON, JR AKA TheRumpledOne |
//|                Support and Resistance                            |
//|                Copyright © 2004  Barry Stander                   |
//|                http://myweb.absa.co.za/stander/4meta/            |
//+------------------------------------------------------------------+
#property copyright "Click here: Barry Stander"
#property link      "http://myweb.absa.co.za/stander/4meta/"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 DarkSalmon 
#property indicator_color4 LightSalmon  
#property indicator_color5 LightSalmon  
#property indicator_color6 DarkSalmon 


//---- input parameters 

extern bool Show.Labels = true ;
extern bool Show.Gauge  = true ;

extern int       WingDing1 = 119;  
extern int       WingDing2 = 119;  
extern int       WingDingSR = 250;  
extern double    iLevelP1=0.382; 
extern double    iLevelP2=0.618; 
extern bool Horizontal = true ;
extern int myChartY = 1 ;


extern color myColor5 = LightSalmon ;
extern color myColor6 = LightSalmon ;
extern color myColor7 = LightSalmon ;
extern color myColor8 = LightSalmon ;

//---- buffers
double v1[];
double v2[];
double val1;
double val2;
double xBuffer1[]; 
double xBuffer2[]; 
double xBuffer3[]; 
double xBuffer4[]; 
double xPos[]; 

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 = "pRes_0" ;
string tSup0 = "pSup_0" ;
string tFib1 = "pFib1_0" ;
string tFib2 = "pFib2_0" ;
string tFib3 = "pFib3_0" ;
string tFib4 = "pFib4_0" ;
string tFib5 = "pFib5_0" ;  
double range  ;
double DynR; 
double DynS;  
datetime StartTime;
int digits ;

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

  IndicatorBuffers(6);
 
//---- drawing settings
 SetIndexArrow(0, WingDingSR);
 SetIndexArrow(1, WingDingSR);
  
   SetIndexStyle(0,DRAW_ARROW,STYLE_DOT,0,Red);
   SetIndexDrawBegin(0,i-1);
   SetIndexBuffer(0, v1);
   SetIndexLabel(0,"Resistance");
    

   SetIndexStyle(1,DRAW_ARROW,STYLE_DOT,0,Blue);
   SetIndexDrawBegin(1,i-1);
   SetIndexBuffer(1, v2);
   SetIndexLabel(1,"Support");
 
 
   SetIndexStyle(2,DRAW_ARROW); 
   SetIndexArrow(2,WingDing2); 
   SetIndexBuffer(2,xBuffer1); 
   SetIndexEmptyValue(2,0.0); 
   SetIndexStyle(3,DRAW_ARROW); 
   SetIndexArrow(3,WingDing1); 
   SetIndexBuffer(3,xBuffer2); 
   SetIndexEmptyValue(3,0.0); 
   SetIndexStyle(4,DRAW_ARROW); 
   SetIndexArrow(4,WingDing1); 
   SetIndexBuffer(4,xBuffer3); 
   SetIndexEmptyValue(4,0.0); 
   SetIndexStyle(5,DRAW_ARROW); 
   SetIndexArrow(5,WingDing2); 
   SetIndexBuffer(5,xBuffer4); 
   SetIndexEmptyValue(5,0.0); 

   tChartPeriod =  TimeFrameToString(Period()) ;

  tLabel01 = "1Resistance" + tChartPeriod ;
  tLabel02 = "2Support" + tChartPeriod ;
  tLabel03 = "3SRMiddle" + tChartPeriod ; 
  tLabel04 = "4Resistance" + tChartPeriod ;
  tLabel05 = "5Support" + tChartPeriod ;
  tLabel06 = "6SRMiddle" + tChartPeriod ; 
  tLabel07 = "7SRMiddle" + tChartPeriod ; 
  
  digits = Digits ;
      
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   
   ObjectDelete("SRFP");
   ObjectDelete("line5SRFP");
   ObjectDelete("R3_lSRFP");
   ObjectDelete("R3_vSRFP");  
   ObjectDelete("R2_lSRFP"); 
   ObjectDelete("R2_vSRFP");
   ObjectDelete("R1_lSRFP");
   ObjectDelete("R1_vSRFP");
   ObjectDelete("Pivot_lSRFP");
   ObjectDelete("Pivot_vSRFP");
   ObjectDelete( "X08_ValueSRF" );
   ObjectDelete(  "X08_LabelSRF" );   
   ObjectDelete(  "X07_ValueSRF" );
   ObjectDelete(  "X07_LabelSRF" );
   ObjectDelete(  "X06_ValueSRF" );
   ObjectDelete(  "X06_LabelSRF" );
   ObjectDelete(  "X05_ValueSRF" );
   ObjectDelete( "X05_LabelSRF" );
   ObjectDelete("Res_SRP");      
   ObjectDelete("Sup_SRP");           
   ObjectDelete("+618_SRP"); 
   ObjectDelete("+382_SRP");      
   ObjectDelete("-618_SRP"); 
   ObjectDelete("-382_SRP");  
   ObjectDelete( "XRN_ValueSRF" );
   ObjectDelete(  "XRN_LabelSRF" );      
   return(0);
  }

int start()
  {
  
   i=Bars;
   while(i>=0)
     {
   

val1 = iFractals(NULL, 0, MODE_UPPER, i); 
//---- 
if(val1 > 0) {
v1[i] = High[i]; 
R3 = v1[i] ; }
else 
if (Horizontal) {v1[i] = v1[i+1]; }

val2 = iFractals(NULL, 0, MODE_LOWER, i); 
//---- 
if(val2 > 0) {
v2[i] = Low[i]; 
R2 = v2[i] ; }
else 
if (Horizontal) {v2[i] = v2[i+1]; }

         double Range = v1[i] - v2[i];    
         xBuffer1[i] = v1[i] + (Range*iLevelP2) ; 
         xBuffer2[i] = v1[i] + (Range*iLevelP1) ; 
         xBuffer3[i] = v2[i] - (Range*iLevelP1) ; 
         xBuffer4[i] = v2[i] - (Range*iLevelP2) ; 
                  
      i--;
     }   
     

X05 = v1[0] + (Range*iLevelP2) ; //fib proj 618+
X06 = v1[0] + (Range*iLevelP1) ; //fib proj 382+     
X07 = v2[0] - (Range*iLevelP1) ; //fib proj 382-
X08 = v2[0] - (Range*iLevelP2) ; //fib proj 618-
  
DynR =   R3; 
DynS =   R2; 
range   = R3 - R2; 
             
xRet = Close[0] - R2 ;

xRetPct =  ( 100 * xRet ) / range;           


if( Show.Labels) DoShowLabels() ;

if( Show.Gauge ) DoShowGauge() ;


   return(0); 
} 



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

void DoShowGauge()
{

string StrX05 = "+Fib618" ; 
string StrX06 = "+Fib382" ; 
string StrX07 = "-Fib382" ; 
string StrX08 = "-Fib618" ;  
string StrXRN = "Range" ;  
  
   color color_pivots_1=White;
   color color_res     =Red;  
   color color_sup     =Blue;   
   color color_ret     =White; 
   color color_retpct  =White;   
    
   color color_r3=Red;
   color color_r2=Red;
   color color_r1=White;
   color color_p =White;
   
   color color_X05=Red;
   color color_X06=Red;
   color color_X07=Red;  
   color color_X08=Red;
   color color_XRN=Yellow;
   
        
	if( Close[0] < R3) { color_r3=Lime; } 
	if( Close[0] < R2) { color_r2=Lime; } 

	if( Close[0] < X05) { color_X05=Lime; } 
	if( Close[0] < X06) { color_X06=Lime; }		
	if( Close[0] < X07) { color_X07=Lime; }	
	if( Close[0] < X08) { color_X08=Lime; } 
	
	int Precision, dig;	

   if( StringFind( Symbol(), "JPY", 0) != -1 ) { Precision = 100; dig = 2;}
   else                                        { Precision = 10000; dig = 4; }

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

   int WindowToUse;
   int Corner_line, Xdist_line;
   int Corner_text, Corner_vSRFP, Xdist_text, Xdist_vSRFP;
   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_XRN ;
  
   int YdistInc ;
    WindowToUse =  0;
    Corner_line = 1;
    Corner_text = 1; Corner_vSRFP = 1;
    Xdist_line = 21; Xdist_text = 93; Xdist_vSRFP = 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_XRN = Ydist_R3 + YdistInc*8;    

   ObjectCreate("SRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("SRFP",tChartPeriod + " SRFP ",9, "Verdana", color_pivots_1);
   ObjectSet("SRFP", OBJPROP_CORNER, Corner_pivots);
   ObjectSet("SRFP", OBJPROP_XDISTANCE, Xdist_pivots);
   ObjectSet("SRFP", OBJPROP_YDISTANCE, Ydist_pivots);
   
   ObjectCreate("line5SRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("line5SRFP","---------------------",7, "Verdana", color_pivots_1);
   ObjectSet("line5SRFP", OBJPROP_CORNER, Corner_line);
   ObjectSet("line5SRFP", OBJPROP_XDISTANCE, Xdist_line);
   ObjectSet("line5SRFP", OBJPROP_YDISTANCE, Ydist_line5);
   
   ObjectCreate("R3_lSRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("R3_lSRFP","Res  ",9, "Verdana", color_res);
   ObjectSet("R3_lSRFP", OBJPROP_CORNER, Corner_text);
   ObjectSet("R3_lSRFP", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("R3_lSRFP", OBJPROP_YDISTANCE, Ydist_R3);
   
   ObjectCreate("R3_vSRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("R3_vSRFP"," "+DoubleToStr(R3,dig),9, "Verdana", color_r3);
   ObjectSet("R3_vSRFP", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("R3_vSRFP", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("R3_vSRFP", OBJPROP_YDISTANCE, Ydist_R3);
   
   ObjectCreate("R2_lSRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("R2_lSRFP","Sup  ",9, "Verdana", color_sup);
   ObjectSet("R2_lSRFP", OBJPROP_CORNER, Corner_text);
   ObjectSet("R2_lSRFP", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("R2_lSRFP", OBJPROP_YDISTANCE, Ydist_R2);
   
   ObjectCreate("R2_vSRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("R2_vSRFP"," "+DoubleToStr(R2,dig),9, "Verdana", color_r2);
   ObjectSet("R2_vSRFP", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("R2_vSRFP", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("R2_vSRFP", OBJPROP_YDISTANCE, Ydist_R2);
   
   ObjectCreate("R1_lSRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("R1_lSRFP","Ret  ",9, "Verdana", color_r1 );
   ObjectSet("R1_lSRFP", OBJPROP_CORNER, Corner_text);
   ObjectSet("R1_lSRFP", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("R1_lSRFP", OBJPROP_YDISTANCE, Ydist_R1);
   
   ObjectCreate("R1_vSRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("R1_vSRFP"," "+DoubleToStr(xRet,dig),9, "Verdana", color_r1);
   ObjectSet("R1_vSRFP", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("R1_vSRFP", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("R1_vSRFP", OBJPROP_YDISTANCE, Ydist_R1);
   
   ObjectCreate("Pivot_lSRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("Pivot_lSRFP","Ret%",9, "Verdana", White);
   ObjectSet("Pivot_lSRFP", OBJPROP_CORNER, Corner_text);
   ObjectSet("Pivot_lSRFP", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("Pivot_lSRFP", OBJPROP_YDISTANCE, Ydist_PV);
   
   ObjectCreate("Pivot_vSRFP", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("Pivot_vSRFP"," "+DoubleToStr(xRetPct,dig),9, "Verdana", color_p);
   ObjectSet("Pivot_vSRFP", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("Pivot_vSRFP", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("Pivot_vSRFP", OBJPROP_YDISTANCE, Ydist_PV);   
   
   ObjectCreate("X05_LabelSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X05_LabelSRF",StrX05,9, "Verdana", myColor5 );
   ObjectSet("X05_LabelSRF", OBJPROP_CORNER, Corner_text);
   ObjectSet("X05_LabelSRF", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X05_LabelSRF", OBJPROP_YDISTANCE, Ydist_X05);
   
   ObjectCreate("X05_ValueSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X05_ValueSRF"," "+DoubleToStr(X05,dig),9, "Verdana", color_X05);
   ObjectSet("X05_ValueSRF", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("X05_ValueSRF", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("X05_ValueSRF", OBJPROP_YDISTANCE, Ydist_X05);
    
   ObjectCreate("X06_LabelSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X06_LabelSRF",StrX06,9, "Verdana", myColor6 );
   ObjectSet("X06_LabelSRF", OBJPROP_CORNER, Corner_text);
   ObjectSet("X06_LabelSRF", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X06_LabelSRF", OBJPROP_YDISTANCE, Ydist_X06);
   
   ObjectCreate("X06_ValueSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X06_ValueSRF"," "+DoubleToStr(X06,dig),9, "Verdana", color_X06);
   ObjectSet("X06_ValueSRF", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("X06_ValueSRF", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("X06_ValueSRF", OBJPROP_YDISTANCE, Ydist_X06);

   ObjectCreate("X07_LabelSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X07_LabelSRF",StrX07,9, "Verdana", myColor7 );
   ObjectSet("X07_LabelSRF", OBJPROP_CORNER, Corner_text);
   ObjectSet("X07_LabelSRF", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X07_LabelSRF", OBJPROP_YDISTANCE, Ydist_X07);
   
   ObjectCreate("X07_ValueSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X07_ValueSRF"," "+DoubleToStr(X07,dig),9, "Verdana", color_X07);
   ObjectSet("X07_ValueSRF", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("X07_ValueSRF", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("X07_ValueSRF", OBJPROP_YDISTANCE, Ydist_X07);

   ObjectCreate("X08_LabelSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X08_LabelSRF",StrX08,9, "Verdana", myColor8 );
   ObjectSet("X08_LabelSRF", OBJPROP_CORNER, Corner_text);
   ObjectSet("X08_LabelSRF", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X08_LabelSRF", OBJPROP_YDISTANCE, Ydist_X08);
   
   ObjectCreate("X08_ValueSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X08_ValueSRF"," "+DoubleToStr(X08,dig),9, "Verdana", color_X08);
   ObjectSet("X08_ValueSRF", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("X08_ValueSRF", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("X08_ValueSRF", OBJPROP_YDISTANCE, Ydist_X08);  
 
   ObjectCreate("XRN_LabelSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("XRN_LabelSRF",StrXRN,9, "Verdana", color_XRN );
   ObjectSet("XRN_LabelSRF", OBJPROP_CORNER, Corner_text);
   ObjectSet("XRN_LabelSRF", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("XRN_LabelSRF", OBJPROP_YDISTANCE, Ydist_XRN);
   
   double xRange = (v1[0] - v2[0]) / Point ;
   
   ObjectCreate("XRN_ValueSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("XRN_ValueSRF"," "+DoubleToStr(xRange,0),9, "Verdana", color_XRN);
   ObjectSet("XRN_ValueSRF", OBJPROP_CORNER, Corner_vSRFP);
   ObjectSet("XRN_ValueSRF", OBJPROP_XDISTANCE, Xdist_vSRFP);
   ObjectSet("XRN_ValueSRF", OBJPROP_YDISTANCE, Ydist_XRN);  

} 


void DoShowLabels()
{

	if(ObjectFind(tRes0) == -1)
		ObjectCreate(tRes0,OBJ_FIBO,0,StartTime,DynR+range,StartTime,DynR);
	else
	{
		ObjectSet(tRes0,OBJPROP_TIME2, StartTime);
		ObjectSet(tRes0,OBJPROP_TIME1, StartTime);
		ObjectSet(tRes0,OBJPROP_PRICE1,DynR+range);
		ObjectSet(tRes0,OBJPROP_PRICE2,DynR);
	}
   ObjectSet(tRes0,OBJPROP_LEVELCOLOR,indicator_color1);
   ObjectSet(tRes0,OBJPROP_FIBOLEVELS,1);
   ObjectSet(tRes0,OBJPROP_FIRSTLEVEL+0,0.0);	
   ObjectSetFiboDescription(tRes0,0, DoubleToStr(DynR,digits)+ " RESISTANCE"); 
   ObjectSet(tRes0,OBJPROP_RAY,true);
   ObjectSet(tRes0,OBJPROP_BACK,true);


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

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

   
		if(ObjectFind(tFib1) == -1)
			ObjectCreate(tFib1,OBJ_FIBO,0,StartTime,DynR,StartTime+PERIOD_H4*60,DynS);
		else
		{
			ObjectSet(tFib1,OBJPROP_TIME2, StartTime);
			ObjectSet(tFib1,OBJPROP_TIME1, StartTime);
			ObjectSet(tFib1,OBJPROP_PRICE1,DynR);
			ObjectSet(tFib1,OBJPROP_PRICE2,DynS);
		}
   	ObjectSet(tFib1,OBJPROP_LEVELCOLOR,indicator_color3); 
   	ObjectSet(tFib1,OBJPROP_FIBOLEVELS,1);
   
   	ObjectSet(tFib1,OBJPROP_FIRSTLEVEL+0,1.618);	
   	ObjectSetFiboDescription(tFib1,0,DoubleToStr(xBuffer1[0],digits)+ " FIB PROJ +1.618 "); 

   	ObjectSet(tFib1,OBJPROP_RAY,true);
   	ObjectSet(tFib1,OBJPROP_BACK,true);
  
   
		if(ObjectFind(tFib2) == -1)
			ObjectCreate(tFib2,OBJ_FIBO,0,StartTime,DynR,StartTime+PERIOD_H4*60,DynS);
		else
		{
			ObjectSet(tFib2,OBJPROP_TIME2, StartTime);
			ObjectSet(tFib2,OBJPROP_TIME1, StartTime);
			ObjectSet(tFib2,OBJPROP_PRICE1,DynR);
			ObjectSet(tFib2,OBJPROP_PRICE2,DynS);
		}
   	ObjectSet(tFib2,OBJPROP_LEVELCOLOR,indicator_color4); 
   	ObjectSet(tFib2,OBJPROP_FIBOLEVELS,2);
   
   	ObjectSet(tFib2,OBJPROP_FIRSTLEVEL+0,1.382);	
   	ObjectSetFiboDescription(tFib2,0,DoubleToStr(xBuffer2[0],digits)+ " FIB PROJ +1.382 "); 

   	ObjectSet(tFib2,OBJPROP_RAY,true);
   	ObjectSet(tFib2,OBJPROP_BACK,true);
 /*
		if(ObjectFind(tFib3) == -1)
			ObjectCreate(tFib3,OBJ_FIBO,0,StartTime,DynR,StartTime+PERIOD_H4*60,DynS);
		else
		{
			ObjectSet(tFib3,OBJPROP_TIME2, StartTime);
			ObjectSet(tFib3,OBJPROP_TIME1, StartTime);
			ObjectSet(tFib3,OBJPROP_PRICE1,DynR);
			ObjectSet(tFib3,OBJPROP_PRICE2,DynS);
		}
   	ObjectSet(tFib3,OBJPROP_LEVELCOLOR,indicator_color5); 
   	ObjectSet(tFib3,OBJPROP_FIBOLEVELS,3);
   
   	ObjectSet(tFib3,OBJPROP_FIRSTLEVEL+0,1.382);	
   	ObjectSetFiboDescription(tFib3,0,DoubleToStr(xBuffer3[0],digits)+ " "+DoubleToStr(iLevel3,3)); 

   	ObjectSet(tFib3,OBJPROP_RAY,true);
   	ObjectSet(tFib3,OBJPROP_BACK,true);
 */       
		if(ObjectFind(tFib4) == -1)
			ObjectCreate(tFib4,OBJ_FIBO,0,StartTime,DynR,StartTime+PERIOD_H4*60,DynS);
		else
		{
			ObjectSet(tFib4,OBJPROP_TIME2, StartTime);
			ObjectSet(tFib4,OBJPROP_TIME1, StartTime);
			ObjectSet(tFib4,OBJPROP_PRICE1,DynR);
			ObjectSet(tFib4,OBJPROP_PRICE2,DynS);
		}
   	ObjectSet(tFib4,OBJPROP_LEVELCOLOR,indicator_color5); 
   	ObjectSet(tFib4,OBJPROP_FIBOLEVELS,4);
   
   	ObjectSet(tFib4,OBJPROP_FIRSTLEVEL+0,-0.382);	
   	ObjectSetFiboDescription(tFib4,0,DoubleToStr(xBuffer3[0],digits)+ " FIB PROJ -1.382 " ); 
   	
   	ObjectSet(tFib4,OBJPROP_RAY,true);
   	ObjectSet(tFib4,OBJPROP_BACK,true);
            
      
		if(ObjectFind(tFib5) == -1)
			ObjectCreate(tFib5,OBJ_FIBO,0,StartTime,DynR,StartTime+PERIOD_H4*60,DynS);
		else
		{
			ObjectSet(tFib5,OBJPROP_TIME2, StartTime);
			ObjectSet(tFib5,OBJPROP_TIME1, StartTime);
			ObjectSet(tFib5,OBJPROP_PRICE1,DynR);
			ObjectSet(tFib5,OBJPROP_PRICE2,DynS);
		}
   	ObjectSet(tFib5,OBJPROP_LEVELCOLOR,indicator_color6); 
   	ObjectSet(tFib5,OBJPROP_FIBOLEVELS,5);
   
   	ObjectSet(tFib5,OBJPROP_FIRSTLEVEL+0,-0.618);	
   	ObjectSetFiboDescription(tFib5,0,DoubleToStr(xBuffer4[0],digits)+ " FIB PROJ -1.618 " ); 

   	ObjectSet(tFib5,OBJPROP_RAY,true);
   	ObjectSet(tFib5,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);
}