//+------------------------------------------------------------------+
//|                                                        Pivot.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window

extern bool ManualCalculation = false;
extern double Yesterday_high = 0;
extern double Yesterday_low  = 0;
extern double Yesterday_close = 0;

double yesterday_high;
double yesterday_low;
double yesterday_close;
double P=0;
double Q=0;
double H8,H7,H6,H5,H4,H3,H2,H1,L1,L2,L3,L4,L5,L6,L7,L8;
double nQ=0;
double nD=0;
double D=0;
double rates_d1[2][6];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
 H8=0; H7=0; H6=0; H5=0; H4=0; H3=0; H2=0; H1=0; L1=0; L2=0; L3=0; L4=0; L5=0; L6=0; L7=0; L8=0;

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here

ObjectDelete("P Label");
ObjectDelete("P Line");

ObjectDelete("H8 Label");
ObjectDelete("H8 Line");
ObjectDelete("H7 Label");
ObjectDelete("H7 Line");
ObjectDelete("H6 Label");
ObjectDelete("H6 Line");
ObjectDelete("H5 Label");
ObjectDelete("H5 Line");
ObjectDelete("H4 Label");
ObjectDelete("H4 Line");
ObjectDelete("H3 Label");
ObjectDelete("H3 Line");
ObjectDelete("H2 Label");
ObjectDelete("H2 Line");
ObjectDelete("H1 Label");
ObjectDelete("H1 Line");
ObjectDelete("L1 Label");
ObjectDelete("L1 Line");
ObjectDelete("L2 Label");
ObjectDelete("L2 Line");
ObjectDelete("L3 Label");
ObjectDelete("L3 Line");
ObjectDelete("L4 Label");
ObjectDelete("L4 Line");
ObjectDelete("L5 Label");
ObjectDelete("L5 Line");
ObjectDelete("L6 Label");
ObjectDelete("L6 Line");
ObjectDelete("L7 Lable");
ObjectDelete("L7 Line");
ObjectDelete("L8 Lable");
ObjectDelete("L8 Line");


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

//---- TODO: add your code here

//---- exit if period is greater than daily charts
if(Period() > 1440)
{
Print("Error - Chart period is greater than 1 day.");
return(-1); // then exit
}

//---- Get new daily prices

ArrayCopyRates(rates_d1, Symbol(), PERIOD_D1);
if ( ManualCalculation == false)
{
yesterday_close = rates_d1[1][4];
yesterday_high = rates_d1[1][3];
yesterday_low = rates_d1[1][2];
}



//---- Calculate Pivots

Q = (yesterday_high - yesterday_low);
P = (yesterday_high + yesterday_low + yesterday_close) / 3;


	H8 = (Q*1.38)+P;
	H7 = (Q*1.23)+P;
	H6 = (Q*1.00)+P;
	H5 = (Q*0.76)+P;
	H4 = (Q*0.62)+P;
	H3 = (Q*0.50)+P;
	H2 = (Q*0.38)+P;
   H1 = (Q*0.23)+P;
	L1 = P-(Q*0.23);
	L2 = P-(Q*0.38);
	L3 = P-(Q*0.50);	
	L4 = P-(Q*0.62);
	L5 = P-(Q*0.76);
	L6 = P-(Q*1.00);
	L7 = P-(Q*1.23);
	L8 = P-(Q*1.38);
	

if (Q > 5) 
{
	nQ = Q;
}
else
{
	nQ = Q*10000;
}

if (D > 5)
{
	nD = D;
}
else
{
	nD = D*10000;
}


Comment("High= ",yesterday_high,"    Previous Days Range= ",nQ,"\nLow= ",yesterday_low,"    Current Days Range= ",nD,"\nClose= ",yesterday_close);

//---- Set line labels on chart window

//---- Pivot Lines


      if(ObjectFind("P label") != 0)
      {
      ObjectCreate("P label", OBJ_TEXT, 0, Time[0], P);
      ObjectSetText("P label", "Daily Pivot", 9, "Arial", White);
      }
      else
      {
      ObjectMove("P label", 0, Time[0], P);
      }


//---  Draw  Pivot lines on chart


      if(ObjectFind("P line") != 0)
      {
      ObjectCreate("P line", OBJ_HLINE, 0, Time[40], P);
      ObjectSet("P line", OBJPROP_STYLE, STYLE_DASH);
      ObjectSet("P line", OBJPROP_WIDTH, 1);
      ObjectSet("P line", OBJPROP_COLOR, White);
      }
      else
      {
      ObjectMove("P line", 0, Time[40], P);
      }



      if(ObjectFind("H8 label") != 0)
      {
      ObjectCreate("H8 label", OBJ_TEXT, 0, Time[10], H8);
      ObjectSetText("H8 label", "R 138% Short Here..Ex Overbought", 9, "Arial", Yellow);
      }
      else
      {
      ObjectMove("H8 label", 0, Time[10], H8);
      }
      
      if(ObjectFind("H7 label") != 0)
      {
      ObjectCreate("H7 label", OBJ_TEXT, 0, Time[10], H7);
      ObjectSetText("H7 label", "R 123% Short Here..Overbought", 9, "Arial", Yellow);
      }
      else
      {
      ObjectMove("H7 label", 0, Time[10], H7);
      }
      
      if(ObjectFind("H6 label") != 0)
      {
      ObjectCreate("H6 label", OBJ_TEXT, 0, Time[10], H6);
      ObjectSetText("H6 label", "R 100% Short Here..Good Resistance", 9, "Arial", Aqua);
      }
      else
      {
      ObjectMove("H6 label", 0, Time[10], H6);
      }
      
      if(ObjectFind("H5 label") != 0)
      {
      ObjectCreate("H5 label", OBJ_TEXT, 0, Time[10], H4);
      ObjectSetText("H5 label", "R 76%", 9, "Arial", Red);
      }
      else
      {
      ObjectMove("H5 label", 0, Time[10], H5);
      }
      
      if(ObjectFind("H4 label") != 0)
      {
      ObjectCreate("H4 label", OBJ_TEXT, 0, Time[10], H4);
      ObjectSetText("H4 label", "R 62%", 9, "Arial", Red);
      }
      else
      {
      ObjectMove("H4 label", 0, Time[10], H4);
      }

      if(ObjectFind("H3 label") != 0)
      {
      ObjectCreate("H3 label", OBJ_TEXT, 0, Time[10], H3);
      ObjectSetText("H3 label", "R 50%", 9, "Arial", Red);
      }
      else
      {
      ObjectMove("H3 label", 0, Time[10], H3);
      }


      if(ObjectFind("H2 label") != 0)
      {
      ObjectCreate("H2 label", OBJ_TEXT, 0, Time[10], H2);
      ObjectSetText("H2 label", "R 38%", 9, "Arial", Magenta);
      }
      else
      {
      ObjectMove("H2 label", 0, Time[10], H2);
      }


      if(ObjectFind("H1 label") != 0)
      {
      ObjectCreate("H1 label", OBJ_TEXT, 0, Time[10], H1);
      ObjectSetText("H1 label", "R 23%", 9, "Arial", Red);
      }
      else
      {
      ObjectMove("H1 label", 0, Time[10], H1);
      }



      if(ObjectFind("L1 label") != 0)
      {
      ObjectCreate("L1 label", OBJ_TEXT, 0, Time[10], L1);
      ObjectSetText("L1 label", "S 23%", 9, "Arial", Lime);
      }
      else
      {
      ObjectMove("L1 label", 0, Time[10], L1);
      }



      if(ObjectFind("L2 label") != 0)
      {
      ObjectCreate("L2 label", OBJ_TEXT, 0, Time[10], L2);
      ObjectSetText("L2 label", "S 38%", 9, "Arial", Magenta);
      }
      else
      {
      ObjectMove("L2 label", 0, Time[10], L2);
      }

      if(ObjectFind("L3 label") != 0)
      {
      ObjectCreate("L3 label", OBJ_TEXT, 0, Time[10], L3);
      ObjectSetText("L3 label", "S 50%", 9, "Arial", Lime);
      }
      else
      {
      ObjectMove("L3 label", 0, Time[10], L3);
      }

      if(ObjectFind("L4 label") != 0)
      {
      ObjectCreate("L4 label", OBJ_TEXT, 0, Time[10], L4);
      ObjectSetText("L4 label", "S 62%", 9, "Arial", Lime);
      }
      else
      {
      ObjectMove("L4 label", 0, Time[10], L4);
      }
      
      if(ObjectFind("L5 label") != 0)
      {
      ObjectCreate("L5 label", OBJ_TEXT, 0, Time[10], L5);
      ObjectSetText("L5 label", "S 76%", 9, "Arial", Lime);
      }
      else
      {
      ObjectMove("L5 label", 0, Time[10], L5);
      }
      
      if(ObjectFind("L6 label") != 0)
      {
      ObjectCreate("L6 label", OBJ_TEXT, 0, Time[10], L6);
      ObjectSetText("L6 label", "S 100% Long Here..Good Support", 9, "Arial", Aqua);
      }
      else
      {
      ObjectMove("L6 label", 0, Time[10], L6);
      }

      if(ObjectFind("L7 label") != 0)
      {
      ObjectCreate("L7 label", OBJ_TEXT, 0, Time[10], L7);
      ObjectSetText("L7 label", "S 123% Long Here..Oversold", 9, "Arial", Yellow);
      }
      else
      {
      ObjectMove("L7 label", 0, Time[10], L7);
      } 
      
      if(ObjectFind("L8 label") != 0)
      {
      ObjectCreate("L8 label", OBJ_TEXT, 0, Time[10], L8);
      ObjectSetText("L8 label", "S 138% Long Here..Ex Oversold", 9, "Arial", Yellow);
      }
      else
      {
      ObjectMove("L8 label", 0, Time[10], L8);
      }
      
//---- Draw Camarilla lines on Chart

      
      if(ObjectFind("H8 line") != 0)
      {
      ObjectCreate("H8 line", OBJ_HLINE, 0, Time[40], H8);
      ObjectSet("H8 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("H8 line", OBJPROP_WIDTH, 3);
      ObjectSet("H8 line", OBJPROP_COLOR, Yellow);
      }
      else
      {
      ObjectMove("H8 line", 0, Time[40], H8);
      }
      
      
      if(ObjectFind("H7 line") != 0)
      {
      ObjectCreate("H7 line", OBJ_HLINE, 0, Time[40], H7);
      ObjectSet("H7 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("H7 line", OBJPROP_WIDTH, 3);
      ObjectSet("H7 line", OBJPROP_COLOR, Yellow);
      }
      else
      {
      ObjectMove("H7 line", 0, Time[40], H7);
      }
      
      
      if(ObjectFind("H6 line") != 0)
      {
      ObjectCreate("H6 line", OBJ_HLINE, 0, Time[40], H6);
      ObjectSet("H6 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("H6 line", OBJPROP_WIDTH, 3);
      ObjectSet("H6 line", OBJPROP_COLOR, Aqua);
      }
      else
      {
      ObjectMove("H6 line", 0, Time[40], H6);
      }
      
      if(ObjectFind("H5 line") != 0)
      {
      ObjectCreate("H5 line", OBJ_HLINE, 0, Time[40], H5);
      ObjectSet("H5 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("H5 line", OBJPROP_WIDTH, 1);
      ObjectSet("H5 line", OBJPROP_COLOR, Red);
      }
      else
      {
      ObjectMove("H5 line", 0, Time[40], H5);
      }
      
      if(ObjectFind("H4 line") != 0)
      {
      ObjectCreate("H4 line", OBJ_HLINE, 0, Time[40], H4);
      ObjectSet("H4 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("H4 line", OBJPROP_WIDTH, 1);
      ObjectSet("H4 line", OBJPROP_COLOR, Red);
      }
      else
      {
      ObjectMove("H4 line", 0, Time[40], H4);
      }

      if(ObjectFind("H3 line") != 0)
      {
      ObjectCreate("H3 line", OBJ_HLINE, 0, Time[40], H3);
      ObjectSet("H3 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("H3 line", OBJPROP_WIDTH, 1);
      ObjectSet("H3 line", OBJPROP_COLOR, Red);
      }
      else
      {
      ObjectMove("H3 line", 0, Time[40], H3);
      }
      
      
      
      if(ObjectFind("H2 line") != 0)
      {
      ObjectCreate("H2 line", OBJ_HLINE, 0, Time[40], H2);
      ObjectSet("H2 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("H2 line", OBJPROP_WIDTH, 3);
      ObjectSet("H2 line", OBJPROP_COLOR, Magenta);
      }
      else
      {
      ObjectMove("H2 line", 0, Time[40], H2);
      }


      if(ObjectFind("H1 line") != 0)
      {
      ObjectCreate("H1 line", OBJ_HLINE, 0, Time[40], H1);
      ObjectSet("H1 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("H1 line", OBJPROP_WIDTH, 1);
      ObjectSet("H1 line", OBJPROP_COLOR, Red);
      }
      else
      {
      ObjectMove("H1 line", 0, Time[40], H1);
      }


      if(ObjectFind("L1 line") != 0)
      {
      ObjectCreate("L1 line", OBJ_HLINE, 0, Time[40], L1);
      ObjectSet("L1 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("L1 line", OBJPROP_WIDTH, 1);
      ObjectSet("L1 line", OBJPROP_COLOR, Lime);
      }
      else
      {
      ObjectMove("L1 line", 0, Time[40], L1);
      }


      if(ObjectFind("L2 line") != 0)
      {
      ObjectCreate("L2 line", OBJ_HLINE, 0, Time[40], L2);
      ObjectSet("L2 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("L2 line", OBJPROP_WIDTH, 3);
      ObjectSet("L2 line", OBJPROP_COLOR, Magenta);
      }
      else
      {
      ObjectMove("L2 line", 0, Time[40], L2);
      }

      if(ObjectFind("L3 line") != 0)
      {
      ObjectCreate("L3 line", OBJ_HLINE, 0, Time[40], L3);
      ObjectSet("L3 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("L3 line", OBJPROP_WIDTH, 1);
      ObjectSet("L3 line", OBJPROP_COLOR, Lime);
      }
      else
      {
      ObjectMove("L3 line", 0, Time[40], L3);
      }


      if(ObjectFind("L4 line") != 0)
      {
      ObjectCreate("L4 line", OBJ_HLINE, 0, Time[40], L4);
      ObjectSet("L4 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("L4 line", OBJPROP_WIDTH, 1);
      ObjectSet("L4 line", OBJPROP_COLOR, Lime);
      }
      else
      {
      ObjectMove("L4 line", 0, Time[40], L4);
      }
      
      
      if(ObjectFind("L5 line") != 0)
      {
      ObjectCreate("L5 line", OBJ_HLINE, 0, Time[40], L5);
      ObjectSet("L5 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("L5 line", OBJPROP_WIDTH, 1);
      ObjectSet("L5 line", OBJPROP_COLOR, Lime);
      }
      else
      {
      ObjectMove("L5 line", 0, Time[40], L5);
      }
      
      
      if(ObjectFind("L6 line") != 0)
      {
      ObjectCreate("L6 line", OBJ_HLINE, 0, Time[40], L6);
      ObjectSet("L6 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("L6 line", OBJPROP_WIDTH, 3);
      ObjectSet("L6 line", OBJPROP_COLOR, Aqua);
      }
      else
      {
      ObjectMove("L6 line", 0, Time[40], L6);
      }
      
      
      if(ObjectFind("L7 line") != 0)
      {
      ObjectCreate("L7 line", OBJ_HLINE, 0, Time[40], L7);
      ObjectSet("L7 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("L7 line", OBJPROP_WIDTH, 3);
      ObjectSet("L7 line", OBJPROP_COLOR, Yellow);
      }
      else
      {
      ObjectMove("L7 line", 0, Time[40], L7);
      }
      
      
      if(ObjectFind("L8 line") != 0)
      {
      ObjectCreate("L8 line", OBJ_HLINE, 0, Time[40], L8);
      ObjectSet("L8 line", OBJPROP_STYLE, STYLE_SOLID);
      ObjectSet("L8 line", OBJPROP_WIDTH, 3);
      ObjectSet("L8 line", OBJPROP_COLOR, Yellow);
      }
      else
      {
      ObjectMove("L8 line", 0, Time[40], L8);
      }
      


//---- End Of Program
   return(0);
  }
//+------------------------------------------------------------------+