//+------------------------------------------------------------------+
//|  SRF       _TRO_SR_FIB_PROJ2                                     |
//|                                                                  | 
//|   Copyright © 2007, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFT AND DONATIONS ACCEPTED                                    | 
//|                                                                  |  
//|    http://docs.mql4.com/constants/wingdings                      |                                         |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, Avery T. Horton, Jr. aka TheRumpledOne"
#property link      "therumpledone@gmail.com"

#property indicator_chart_window 
#property indicator_buffers 6

#property indicator_color1 White 
#property indicator_color2 Lime
#property indicator_color3 MediumTurquoise 
#property indicator_color4 Red
#property indicator_color5 Yellow
#property indicator_color6 Orange
#property indicator_color7 OrangeRed

//---- For the small screens
//extern string    Display_infos         = "=== If true, displayed on the chart ===";
//extern bool      display_on_chart      =  true ;  // If true, the open trade analysis, daily pivots and daily range will be displayed on the chart window

// indicators parameters

extern bool iPlotChart = true ;
extern bool iPlotGauge = true ;

extern int myPeriod  = 1440 ;
extern int myOffset  = 1 ; 
extern int myChartY = 1 ;
 
extern double    iLevelP1=0.382; 
extern double    iLevelP2=0.618; 
extern bool      Horizontal = true ;

extern int myStyle1  = 2 ;
extern int myStyle2  = 2 ;
extern int myStyle3  = 2 ;
extern int myStyle4  = 2 ;
extern int myStyle5  = 2 ;
extern int myStyle6  = 2 ;
extern int myStyle7  = 2 ;

extern int myWingDing1  = 226 ;
extern int myWingDing2  = 225 ;
extern int myWingDing3  = 234 ;
extern int myWingDing4  = 233 ;
extern int myWingDing5  = 115 ;
extern int myWingDing6  = 115 ;
extern int myWingDing7  = 115 ;

extern color myColor1 = LightSalmon ;
extern color myColor2 = LightSalmon ;
extern color myColor3 = Blue;
extern color myColor4 = Red;
extern color myColor5 = LightSalmon ;
extern color myColor6 = LightSalmon ;
extern color myColor7 = White;
extern color myColor8 = White;

//---- buffers

double P1Buffer[];
double P2Buffer[];
double P3Buffer[];
double P4Buffer[];
double P5Buffer[];
double P6Buffer[];
double P7Buffer[];

double yesterday_high=0;
double yesterday_open=0;
double yesterday_low=0;
double yesterday_close=0;
double today_open=0;
double today_high=0;
double today_low=0;

double v1[];
double v2[];
double val1;
double val2;

int i;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- name for indicator window

   string short_name=" ";
   IndicatorShortName(short_name);
   SetIndexBuffer(0, P1Buffer);
   SetIndexBuffer(1, P2Buffer);
   SetIndexBuffer(2, P3Buffer);
   SetIndexBuffer(3, P4Buffer);
   SetIndexBuffer(4, P5Buffer);
   SetIndexBuffer(5, P6Buffer);
   SetIndexBuffer(6, P7Buffer);
   
//----

SetIndexArrow(0, myWingDing1); 
SetIndexArrow(1, myWingDing2); 
SetIndexArrow(2, myWingDing3); 
SetIndexArrow(3, myWingDing4); 
SetIndexArrow(4, myWingDing5); 
SetIndexArrow(5, myWingDing6); 
SetIndexArrow(6, myWingDing7); 

   SetIndexStyle(0, DRAW_ARROW, myStyle1, 1);
   SetIndexStyle(1, DRAW_ARROW, myStyle2, 1);   
   SetIndexStyle(2, DRAW_ARROW, myStyle3, 1);
   SetIndexStyle(3, DRAW_ARROW, myStyle4, 1);
   SetIndexStyle(4, DRAW_ARROW, myStyle5, 1);
   SetIndexStyle(5, DRAW_ARROW, myStyle6, 1);
   SetIndexStyle(6, DRAW_ARROW, myStyle7, 1); 

SetIndexLabel(0, "proj 618");
SetIndexLabel(1, "fib proj 382");
SetIndexLabel(2, "Resistance");
SetIndexLabel(3, "Support");
SetIndexLabel(4, "fib proj 382-");
SetIndexLabel(5, "fib proj 618-");
SetIndexLabel(6, "retrace amount");
 
  
     
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   
   ObjectDelete("SRF");
   ObjectDelete("line5SRF");
   ObjectDelete("X01_LabelSRF");
   ObjectDelete("X01_ValueSRF");
   ObjectDelete("X02_LabelSRF");
   ObjectDelete("X02_ValueSRF");
   ObjectDelete("X03_LabelSRF");
   ObjectDelete("X03_ValueSRF");
   ObjectDelete("X04_LabelSRF");
   ObjectDelete("X04_ValueSRF");
   ObjectDelete("X05_LabelSRF");
   ObjectDelete("X05_ValueSRF");
   ObjectDelete("X06_LabelSRF");
   ObjectDelete("X06_ValueSRF");
   ObjectDelete("X07_LabelSRF");
   ObjectDelete("X07_ValueSRF");
   ObjectDelete("X08_LabelSRF");
   ObjectDelete("X08_ValueSRF");
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

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

val1 = iFractals(NULL, myPeriod, MODE_UPPER, i); 

if(val1 > 0) {v1[i] = High[i]; double R3 = v1[i] ; }
else if (Horizontal) {v1[i] = v1[i+1]; }

val2 = iFractals(NULL, myPeriod, MODE_LOWER, i); 

if(val2 > 0) { v2[i] = Low[i]; double R2 = v2[i] ; }
else if (Horizontal) {v2[i] = v2[i+1]; }

   double xRange = v1[i] - v2[i];   
  
   double X01 = v1[i] + (xRange*iLevelP2) ; //fib proj 618+
   double X02 = v1[i] + (xRange*iLevelP1) ; //fib proj 382+

	double X03 = v1[i]                    ; 	// Resistance	
   double X04 = v2[i]                    ; 	// Support

   double X05 = v2[i] - (xRange*iLevelP1) ; //fib proj 382-
   double X06 = v2[i] - (xRange*iLevelP2) ; //fib proj 618-
	double X07 = Close[0] - X04           ; // retrace amount
if( xRange != 0 ){   double X08 = ( 100 * X07 ) / ( xRange ); } // retrace percent

 
if ( iPlotChart ) { 
 	
	P1Buffer[i] = X01 ;
 	P2Buffer[i] = X02 ;
   P3Buffer[i] = X03 ;
  	P4Buffer[i] = X04 ;
	P5Buffer[i] = X05 ;
   P6Buffer[i] = X06 ;
//   P7Buffer[i] = X07 ;
   
} // iPlotChart

      i--;
      
} // FOR 

  
if ( iPlotGauge ) {         
    
string StrX01 = "+Fib618" ; 
string StrX02 = "+Fib382" ; 
string StrX03 = "Res" ; 
string StrX04 = "Sup" ; 
string StrX05 = "-Fib382" ; 
string StrX06 = "-Fib618" ; 
string StrX07 = "Ret" ; 
string StrX08 = "Ret%" ;

   color color_SRF_1=Orchid;
                
   color color_X01=Red;
   color color_X02=Red;
   color color_X03=Red;
   color color_X04=Red;
   color color_X05=Red;
   color color_X06=Red;
   color color_X07=Red;  
   color color_X08=Red;
      	
	if( Close[0] < X01) { color_X01=Lime; } 
	if( Close[0] < X02) { color_X02=Lime; } 	
	if( Close[0] < X03) { color_X03=Lime; } 
	if( Close[0] < X04) { color_X04=Lime; } 
	if( Close[0] < X05) { color_X05=Lime; } 
	if( Close[0] < X06) { color_X06=Lime; }		
//	if( Close[0] < X07) { color_X07=Lime; }		
		
	int Precision, dig;	

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

int sPeriod= Period();

if (myPeriod != NULL){ sPeriod= myPeriod ;}
       	
//---- Set labels

   int WindowToUse;
   int Corner_line, Xdist_line;
   int Corner_text, Corner_ValueSRF, Xdist_text, Xdist_ValueSRF;
   int Ydist_line5;
   int Corner_pivots, Xdist_pivots, Ydist_pivots;
   int Ydist_X01, Ydist_X02, Ydist_X03, Ydist_X04, Ydist_X05, Ydist_X06, Ydist_X07, Ydist_X08 ;
   int YdistInc ;
   
    WindowToUse =  0;
    Corner_line = 1;
    Corner_text = 1; 
    Corner_ValueSRF = 1;
    Xdist_line = 21; 
    Xdist_text = 93; 
    Xdist_ValueSRF = 23;
    Corner_pivots = 1; 
    Xdist_pivots = 21; 
    
    Ydist_pivots = myChartY;  
    Ydist_line5 = 
    Ydist_pivots + 11; 
    YdistInc = 15 ;
    Ydist_X01 = Ydist_pivots + 25; 
    Ydist_X02 = Ydist_X01 + YdistInc; 
    Ydist_X03 = Ydist_X01 + YdistInc*2; 
    Ydist_X04 = Ydist_X01 + YdistInc*3; 
    Ydist_X05 = Ydist_X01 + YdistInc*4; 
    Ydist_X06 = Ydist_X01 + YdistInc*5; 
    Ydist_X07 = Ydist_X01 + YdistInc*6;
    Ydist_X08 = Ydist_X01 + YdistInc*7;
    
   ObjectCreate("SRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("SRF",sPeriod + " SRF ",9, "Verdana", color_SRF_1);
   ObjectSet("SRF", OBJPROP_CORNER, Corner_pivots);
   ObjectSet("SRF", OBJPROP_XDISTANCE, Xdist_pivots);
   ObjectSet("SRF", OBJPROP_YDISTANCE, Ydist_pivots);
   
   ObjectCreate("line5SRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("line5SRF","---------------------",7, "Verdana", color_SRF_1);
   ObjectSet("line5SRF", OBJPROP_CORNER, Corner_line);
   ObjectSet("line5SRF", OBJPROP_XDISTANCE, Xdist_line);
   ObjectSet("line5SRF", OBJPROP_YDISTANCE, Ydist_line5);
   
   ObjectCreate("X01_LabelSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X01_LabelSRF",StrX01,9, "Verdana", myColor1);
   ObjectSet("X01_LabelSRF", OBJPROP_CORNER, Corner_text);
   ObjectSet("X01_LabelSRF", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X01_LabelSRF", OBJPROP_YDISTANCE, Ydist_X01);
   
   ObjectCreate("X01_ValueSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X01_ValueSRF"," "+DoubleToStr(X01,dig),9, "Verdana", color_X01);
   ObjectSet("X01_ValueSRF", OBJPROP_CORNER, Corner_ValueSRF);
   ObjectSet("X01_ValueSRF", OBJPROP_XDISTANCE, Xdist_ValueSRF);
   ObjectSet("X01_ValueSRF", OBJPROP_YDISTANCE, Ydist_X01);
   
   ObjectCreate("X02_LabelSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X02_LabelSRF",StrX02,9, "Verdana", myColor2);
   ObjectSet("X02_LabelSRF", OBJPROP_CORNER, Corner_text);
   ObjectSet("X02_LabelSRF", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X02_LabelSRF", OBJPROP_YDISTANCE, Ydist_X02);
   
   ObjectCreate("X02_ValueSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X02_ValueSRF"," "+DoubleToStr(X02,dig),9, "Verdana", color_X02);
   ObjectSet("X02_ValueSRF", OBJPROP_CORNER, Corner_ValueSRF);
   ObjectSet("X02_ValueSRF", OBJPROP_XDISTANCE, Xdist_ValueSRF);
   ObjectSet("X02_ValueSRF", OBJPROP_YDISTANCE, Ydist_X02);
 
   ObjectCreate("X03_LabelSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X03_LabelSRF",StrX03,9, "Verdana", myColor3 );
   ObjectSet("X03_LabelSRF", OBJPROP_CORNER, Corner_text);
   ObjectSet("X03_LabelSRF", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X03_LabelSRF", OBJPROP_YDISTANCE, Ydist_X03);
   
   ObjectCreate("X03_ValueSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X03_ValueSRF"," "+DoubleToStr(X03,dig),9, "Verdana", color_X03);
   ObjectSet("X03_ValueSRF", OBJPROP_CORNER, Corner_ValueSRF);
   ObjectSet("X03_ValueSRF", OBJPROP_XDISTANCE, Xdist_ValueSRF);
   ObjectSet("X03_ValueSRF", OBJPROP_YDISTANCE, Ydist_X03);

   ObjectCreate("X04_LabelSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X04_LabelSRF",StrX04,9, "Verdana", myColor4 );
   ObjectSet("X04_LabelSRF", OBJPROP_CORNER, Corner_text);
   ObjectSet("X04_LabelSRF", OBJPROP_XDISTANCE, Xdist_text);
   ObjectSet("X04_LabelSRF", OBJPROP_YDISTANCE, Ydist_X04);
   
   ObjectCreate("X04_ValueSRF", OBJ_LABEL, WindowToUse, 0, 0);
   ObjectSetText("X04_ValueSRF"," "+DoubleToStr(X04,dig),9, "Verdana", color_X04);
   ObjectSet("X04_ValueSRF", OBJPROP_CORNER, Corner_ValueSRF);
   ObjectSet("X04_ValueSRF", OBJPROP_XDISTANCE, Xdist_ValueSRF);
   ObjectSet("X04_ValueSRF", OBJPROP_YDISTANCE, Ydist_X04);

   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_ValueSRF);
   ObjectSet("X05_ValueSRF", OBJPROP_XDISTANCE, Xdist_ValueSRF);
   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_ValueSRF);
   ObjectSet("X06_ValueSRF", OBJPROP_XDISTANCE, Xdist_ValueSRF);
   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_ValueSRF);
   ObjectSet("X07_ValueSRF", OBJPROP_XDISTANCE, Xdist_ValueSRF);
   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_ValueSRF);
   ObjectSet("X08_ValueSRF", OBJPROP_XDISTANCE, Xdist_ValueSRF);
   ObjectSet("X08_ValueSRF", OBJPROP_YDISTANCE, Ydist_X08);

} // iPlotGauge
    
   return(0);
  }