//+------------------------------------------------------------------+
//|                                             ForexMasterMaker.com |
//|                                                       Pivots.mq4 |
//+------------------------------------------------------------------+

#property copyright "ForexMasterMaker.com, © 2005"
#property link      "http://www.forexmastermaker.com."

#property indicator_chart_window
//---- input parameters
extern int    GMTshift=7;
extern bool   Use_Manual = true;
extern double Yesterdays_High = 1.43160;
extern double Yesterdays_Low = 1.42070;
extern double Yesterdays_Close = 1.42558;
extern int font_size = 8;
extern color Lines_Color = Red;
extern color Fonts_Color = Red;
extern bool Show_Pivot_Line = true;
extern color Pivot_Color = Cyan;
extern color PivotFont_Color = Red;
extern bool Show_Info = true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//---- TODO: add your code here
double day_high=0;
double day_low=0;
double yesterday_high=0;
double yesterday_open=0;
double yesterday_low=0;
double yesterday_close=0;
double today_open=0;

double P=0,S=0,R=0,S1=0,H4=0,S2=0,R2=0,S3=0,L4=0,nQ=0,nD=0,D=0;
double H3,H2,H1,L1,L2,L3,H5,L5;
int cnt=720;
double cur_day=0;
double prev_day=0;

double rates_d1[2][6];

int index;
string commentstr;

//---- 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 & calculate pivots

while (cnt!= 0)
{
	cur_day = TimeDay(Time[cnt]- (GMTshift*3600));
	
	if (prev_day != cur_day)
	{

		yesterday_close = Close[cnt+1];
		today_open = Open[cnt];
		yesterday_high = day_high;
		yesterday_low = day_low;
		
		day_high = High[cnt];
		day_low  = Low[cnt];

		prev_day = cur_day;
	   if(Use_Manual == true)
	   {
	     yesterday_high = Yesterdays_High;
	     yesterday_low = Yesterdays_Low;
	     yesterday_close = Yesterdays_Close;
	   }		
	}
   
   if (High[cnt]>day_high)
   {
      day_high = High[cnt];
   }
   if (Low[cnt]<day_low)
   {
      day_low = Low[cnt];
   }
	
//	SetIndexValue(cnt, 0);
	cnt--;

}

D = (day_high - day_low);
//------ Pivot Points ------

P = (yesterday_high + yesterday_low + yesterday_close)/3;
H5 = (yesterday_high/yesterday_low)*yesterday_close;
H4 = ((yesterday_high - yesterday_low)* D4) + yesterday_close;
H3 = ((yesterday_high - yesterday_low)* D3) + yesterday_close;
L3 = yesterday_close - ((yesterday_high - yesterday_low)*(D3));
L4 = yesterday_close - ((yesterday_high - yesterday_low)*(D4));
L5 = yesterday_close - (H5 - yesterday_close);

//------ DRAWING LINES ------

Comment("Camarilla Levels by www.ForexMasterMaker.com");
commentstr = "Yesterdays High : "+yesterday_high+"\nYesterdays Low : "+yesterday_low+"\nYesterdays Close : "+yesterday_close+"\nPivots : "+DoubleToStr(P,Digits);
if(Show_Info == true)
{
   Comment(commentstr);
}
else if(Show_Info == false)
{
   index = StringFind(commentstr,"Yesterdays High", 0);
   if(index != -1)
   {
      Comment("");
   }   
}
ObjectDelete("L5_Line");
ObjectDelete("L4_Line");
ObjectDelete("L3_Line");

ObjectDelete("H3_Line");
ObjectDelete("H4_Line");
ObjectDelete("H5_Line");

ObjectDelete("P_Line");
if(Show_Pivot_Line==true)
{
   ObjectCreate("P_Line", OBJ_HLINE,0, CurTime(),P);
   ObjectSet("P_Line",OBJPROP_COLOR,Pivot_Color);
   ObjectSet("P_Line",OBJPROP_STYLE,STYLE_DASH);
}

ObjectCreate("L5_Line", OBJ_HLINE,0, CurTime(),L5);
ObjectSet("L5_Line",OBJPROP_COLOR,Lines_Color);
ObjectSet("L5_Line",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate("L4_Line", OBJ_HLINE,0, CurTime(),L4);
ObjectSet("L4_Line",OBJPROP_COLOR,Lines_Color);
ObjectSet("L4_Line",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate("L3_Line", OBJ_HLINE,0, CurTime(),L3);
ObjectSet("L3_Line",OBJPROP_COLOR,Lines_Color);
ObjectSet("L3_Line",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate("H3_Line", OBJ_HLINE,0, CurTime(),H3);
ObjectSet("H3_Line",OBJPROP_COLOR,SpringGreen);
ObjectSet("H3_Line",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate("H4_Line", OBJ_HLINE,0, CurTime(),H4);
ObjectSet("H4_Line",OBJPROP_COLOR,SpringGreen);
ObjectSet("H4_Line",OBJPROP_STYLE,STYLE_SOLID);

ObjectCreate("H5_Line", OBJ_HLINE,0, CurTime(),H5);
ObjectSet("H5_Line",OBJPROP_COLOR,SpringGreen);
ObjectSet("H5_Line",OBJPROP_STYLE,STYLE_SOLID);

ObjectsRedraw();

// --- Typing Labels

if(ObjectFind("L3 label") != 0)
{
ObjectCreate("L3 label", OBJ_TEXT, 0, Time[0], L3);
ObjectSetText("L3 label", " L3 SHORT ", font_size, "Arial", Fonts_Color);
}
else
{
ObjectMove("L3 label", 0, Time[0], L3);
}
   
if(ObjectFind("L4 label") != 0)
{
ObjectCreate("L4 label", OBJ_TEXT, 0, Time[0], L4);
ObjectSetText("L4 label", " L4 SHORT BREAKOUT ", font_size, "Arial", Fonts_Color);
}
else
{
ObjectMove("L4 label", 0, Time[0], L4);
}

if(ObjectFind("L5 label") != 0)
{
ObjectCreate("L5 label", OBJ_TEXT, 0, Time[0], L5);
ObjectSetText("L5 label", " L5 SB TARGET", font_size, "Arial", Fonts_Color);
}
else
{
ObjectMove("L5 label", 0, Time[0], L5);
}

 if(ObjectFind("H5 label") != 0)
{
ObjectCreate("H5 label", OBJ_TEXT, 0, Time[0], H5);
ObjectSetText("H5 label", " H5 LB TARGET", font_size, "Arial", Fonts_Color);
}
else
{
ObjectMove("H5 label", 0, Time[0], H5);
}

 if(ObjectFind("H4 label") != 0)
{
ObjectCreate("H4 label", OBJ_TEXT, 0, Time[0], H4);
ObjectSetText("H4 label", " H4 LONG BREAKOUT", font_size, "Arial", Fonts_Color);
}
else
{
ObjectMove("H4 label", 0, Time[0], H4);
}

 if(ObjectFind("H3 label") != 0)
{
ObjectCreate("H3 label", OBJ_TEXT, 0, Time[0], H3);
ObjectSetText("H3 label", " H3 SHORT", font_size, "Arial", Fonts_Color);
}
else
{
ObjectMove("H3 label", 0, Time[0], H3);
}

if(ObjectFind("P label") != 0)
{
ObjectCreate("P label", OBJ_TEXT, 0, Time[0], P);
ObjectSetText("P label", " PIVOT ", font_size, "Arial", PivotFont_Color);
}
else
{
ObjectMove("P label", 0, Time[0], P);
}  
   return(0);
 }
 //+------------------------------------------------------------------+

