Navigation:Home > Content >

PivotsV2.mq4

Time: 2016-05-19 | Download file:PivotsV2.mq4

//+------------------------------------------------------------------+
//|                                                 camarilladt8.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//| Fixed Sunday/Monday problem                                      |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
//---- input parameters
extern bool Alerts = false;
extern int  GMTshift = 0;
extern int LabelShift = 20;
extern int LineShift = 40;
extern bool Pivot = true;
extern color PivotColor = Yellow;
extern color PivotFontColor = White;
extern int PivotFontSize = 8;
extern int PivotWidth = 1;
extern int PipDistance = 20;
extern bool Cams = false;
extern color CamFontColor = White;
extern int CamFontSize = 10;
extern bool Fibs = false;
extern color FibColor = GreenYellow;
extern color FibFontColor = White;
extern int FibFontSize = 8;
extern bool StandardPivots = true;
extern color StandardFontColor = White;
extern int StandardFontSize = 8;
extern color SupportColor = White;
extern color ResistanceColor = FireBrick;
extern bool MidPivots = false;
extern color MidPivotColor = White;
extern int MidFontSize = 8;

datetime LabelShiftTime, LineShiftTime;
double P, H3, H4, H5;
double L3, L4, L5;
double LastHigh,LastLow,x;
double day_high;
double day_low;
double yesterday_open;
double today_open;
double cur_day;
double prev_day;
bool firstL3=true;
bool firstH3=true;

double D1=0.091667;
double D2=0.183333;
double D3=0.2750;
double D4=0.55;


// Fib variables

double yesterday_high=0;
double yesterday_low=0;
double yesterday_close=0;
double r1=0;
double r2=0;
double r3=0;
double r4=0;
double r5=0;
double r6=0;
double r7=0;
double p=0;
double s1=0;
double s2=0;
double s3=0;
double s4=0;
double s5=0;
double s6=0;
double s7=0;
double R;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
if (Fibs)
{
ObjectDelete("FibR1 Label"); 
ObjectDelete("FibR1 Line");
ObjectDelete("FibR2 Label");
ObjectDelete("FibR2 Line");
ObjectDelete("FibR3 Label");
ObjectDelete("FibR3 Line");
ObjectDelete("FibR4 Label"); 
ObjectDelete("FibR4 Line");
ObjectDelete("FibR5 Label");
ObjectDelete("FibR5 Line");
ObjectDelete("FibR6 Label");
ObjectDelete("FibR6 Line");
ObjectDelete("FibR7 Label");
ObjectDelete("FibR7 Line");


ObjectDelete("FibS1 Label");
ObjectDelete("FibS1 Line");
ObjectDelete("FibS2 Label");
ObjectDelete("FibS2 Line");
ObjectDelete("FibS3 Label");
ObjectDelete("FibS3 Line");
ObjectDelete("FibS4 Label");
ObjectDelete("FibS4 Line");
ObjectDelete("FibS5 Label");
ObjectDelete("FibS5 Line");
ObjectDelete("FibS6 Label");
ObjectDelete("FibS6 Line");
ObjectDelete("FibS7 Label");
ObjectDelete("FibS7 Line");
}
if (Pivot)
{
ObjectDelete("P Label");
ObjectDelete("P Line");
}
if (Cams)
{
ObjectDelete("H5 Label");
ObjectDelete("H5 Line");
ObjectDelete("H4 Label");
ObjectDelete("H4 Line");
ObjectDelete("H3 Label");
ObjectDelete("H3 Line");
ObjectDelete("L3 Label");
ObjectDelete("L3 Line");
ObjectDelete("L4 Label");
ObjectDelete("L4 Line");
ObjectDelete("L5 Label");
ObjectDelete("L5 Line");
}
//----
if (StandardPivots)
{
ObjectDelete("R1 Label"); 
ObjectDelete("R1 Line");
ObjectDelete("R2 Label");
ObjectDelete("R2 Line");
ObjectDelete("R3 Label");
ObjectDelete("R3 Line");
ObjectDelete("S1 Label");
ObjectDelete("S1 Line");
ObjectDelete("S2 Label");
ObjectDelete("S2 Line");
ObjectDelete("S3 Label");
ObjectDelete("S3 Line");
}
if (MidPivots)
{
ObjectDelete("M5 Label");
ObjectDelete("M5 Line");
ObjectDelete("M4 Label");
ObjectDelete("M4 Line");
ObjectDelete("M3 Label");
ObjectDelete("M3 Line");
ObjectDelete("M2 Label");
ObjectDelete("M2 Line");
ObjectDelete("M1 Label");
ObjectDelete("M1 Line");
ObjectDelete("M0 Label");
ObjectDelete("M0 Line");

}
Comment ("");

   return(0);
  }

int DoAlerts()
{
   double DifAboveL3,PipsLimit;
   double DifBelowH3;

   DifBelowH3 = H3 - Close[0];
   DifAboveL3 = Close[0] - L3;
   PipsLimit = PipDistance*Point;
   
   if (DifBelowH3 > PipsLimit) firstH3 = true;
   if (DifBelowH3 <= PipsLimit && DifBelowH3 > 0)
   {
    if (firstH3)
    {
      Alert("Below Cam H3 Line by ",DifBelowH3, " for ", Symbol(),"-",Period());
      PlaySound("alert.wav");
      firstH3=false;
    }
   }

   if (DifAboveL3 > PipsLimit) firstL3 = true;
   if (DifAboveL3 <= PipsLimit && DifAboveL3 > 0)
   {
    if (firstL3)
    {
      Alert("Above Cam L3 Line by ",DifAboveL3," for ", Symbol(),"-",Period());
      Sleep(2000);
      PlaySound("timeout.wav");
      firstL3=false;
    }
   }
   
}


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//---- TODO: add your code here
double Q=0,S=0,R=0,M2=0,M3=0,S1=0,R1=0,M1=0,M4=0,S2=0,R2=0,M0=0,M5=0,S3=0,R3=0,nQ=0,nD=0,D=0;

int cnt=720;

//---- 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
 day_high=0;
 day_low=0;
 yesterday_open=0;
 today_open=0;
 cur_day=0;
 prev_day=0;

while (cnt!= 0)
{
	if (TimeDayOfWeek(Time[cnt]) == 0)
	{
     cur_day = prev_day;
	}
	else
	{
     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 (High[cnt]>day_high)
   {
      day_high = High[cnt];
   }
   if (Low[cnt] 5) 
{
	nQ = Q;
}
else
{
	nQ = Q*10000;
}

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

 if (StringSubstr(Symbol(),3,3)=="JPY")
      {
      nQ=nQ/100;
      nD=nD/100;
      }

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

LabelShiftTime = Time[LabelShift];
LineShiftTime = Time[LineShift];

   if (Pivot)
   {
      DisplayLabel("P label", "Pivot", P, PivotFontSize, PivotFontColor);
      DisplayLine("P line", P, 0, STYLE_DASH, PivotColor);
   }

  if (StandardPivots)
  {
      DisplayLabel("R1 label", "R1", R1, StandardFontSize, StandardFontColor);
      DisplayLabel("R2 label", "R2", R2, StandardFontSize, StandardFontColor);
      DisplayLabel("R3 label", "R3", R3, StandardFontSize, StandardFontColor);
      DisplayLabel("S1 label", "S1", S1, StandardFontSize, StandardFontColor);
      DisplayLabel("S2 label", "S2", S2, StandardFontSize, StandardFontColor);
      DisplayLabel("S3 label", "S3", S3, StandardFontSize, StandardFontColor);


      DisplayLine("S1 line", S1, 0, STYLE_DASHDOTDOT, SupportColor);
      DisplayLine("S2 line", S2, 0, STYLE_DASHDOTDOT, SupportColor);
      DisplayLine("S3 line", S3, 0, STYLE_DASHDOTDOT, SupportColor);

      DisplayLine("R1 line", R1, 0, STYLE_DASHDOTDOT, ResistanceColor);
      DisplayLine("R2 line", R2, 0, STYLE_DASHDOTDOT, ResistanceColor);
      DisplayLine("R3 line", R3, 0, STYLE_DASHDOTDOT, ResistanceColor);
  }
  
  if (MidPivots)
  {
      DisplayLabel("M5 label", " M5", M5, MidFontSize, MidPivotColor);
      DisplayLabel("M4 label", " M4", M4, MidFontSize, MidPivotColor);
      DisplayLabel("M3 label", " M3", M3, MidFontSize, MidPivotColor);
      DisplayLabel("M2 label", " M2", M2, MidFontSize, MidPivotColor);
      DisplayLabel("M1 label", " M1", M1, MidFontSize, MidPivotColor);
      DisplayLabel("M0 label", " M0", M0, MidFontSize, MidPivotColor);

      DisplayLine("M5 line", M5, 0, STYLE_DASHDOTDOT, MidPivotColor);
      DisplayLine("M4 line", M4, 0, STYLE_DASHDOTDOT, MidPivotColor);
      DisplayLine("M3 line", M3, 0, STYLE_DASHDOTDOT, MidPivotColor);
      DisplayLine("M2 line", M2, 0, STYLE_DASHDOTDOT, MidPivotColor);
      DisplayLine("M1 line", M1, 0, STYLE_DASHDOTDOT, MidPivotColor);
      DisplayLine("M0 line", M0, 0, STYLE_DASHDOTDOT, MidPivotColor);
  }
  
  if (Fibs)
  {
      DisplayLabel("FibR1 label", "Fib R1 23.6", r1, FibFontSize, FibFontColor);
      DisplayLabel("FibR2 label", "Fib R2 38.2", r2, FibFontSize, FibFontColor);
      DisplayLabel("FibR3 label", "Fib R3 50", r3, FibFontSize, FibFontColor);
      DisplayLabel("FibR4 label", "Fib R4 61.8", r4, FibFontSize, FibFontColor);
      DisplayLabel("FibR5 label", "Fib R5 100", r5, FibFontSize, FibFontColor);
      DisplayLabel("FibR6 label", "Fib R6 138.2", r6, FibFontSize, FibFontColor);
      DisplayLabel("FibR7 label", "Fib R7 161.8", r7, FibFontSize, FibFontColor);
      DisplayLabel("FibS1 label", "Fib S1 23.6", s1, FibFontSize, FibFontColor);
      DisplayLabel("FibS2 label", "Fib S2 38.2", s2, FibFontSize, FibFontColor);
      DisplayLabel("FibS3 label", "Fib S3 50", s3, FibFontSize, FibFontColor);
      DisplayLabel("FibS4 label", "Fib S4 61.8", s4, FibFontSize, FibFontColor);
      DisplayLabel("FibS5 label", "Fib S5 100", s5, FibFontSize, FibFontColor);
      DisplayLabel("FibS6 label", "Fib S6 138.2", s6, FibFontSize, FibFontColor);
      DisplayLabel("FibS7 label", "Fib S7 161.8", s7, FibFontSize, FibFontColor);

      DisplayLine("FibR1 line", r1, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibR2 line", r2, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibR3 line", r3, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibR4 line", r4, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibR5 line", r5, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibR6 line", r6, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibR7 line", r7, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibS1 line", s1, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibS2 line", s2, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibS3 line", s3, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibS4 line", s4, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibS5 line", s5, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibS6 line", s6, 0, STYLE_DASHDOTDOT, FibColor);
      DisplayLine("FibS7 line", s7, 0, STYLE_DASHDOTDOT, FibColor);
  }


  if (Cams)
  {
// --- THE CAMARILLA ---
      DisplayLabel("H5 label", " H5 LB TARGET", H5, CamFontSize, CamFontColor);
      DisplayLabel("H4 label", " H4 LONG BREAKOUT", H4, CamFontSize, CamFontColor);
      DisplayLabel("H3 label", " H3 SHORT", H3, CamFontSize, CamFontColor);
      DisplayLabel("L3 label", " L3 LONG", L3, CamFontSize, CamFontColor);
      DisplayLabel("L4 label", " L4 SHORT BREAKOUT", L4, CamFontSize, CamFontColor);
      DisplayLabel("L5 label", " L5 SB TARGET", L5, CamFontSize, CamFontColor);
      
      DisplayLine("H5 line", H5, 1, STYLE_SOLID, SpringGreen);
      DisplayLine("H4 line", H4, 1, STYLE_SOLID, SpringGreen);
      DisplayLine("H3 line", H3, 2, STYLE_SOLID, SpringGreen);
      DisplayLine("L5 line", L5, 1, STYLE_SOLID, Red);
      DisplayLine("L4 line", L4, 1, STYLE_SOLID, Red);
      DisplayLine("L3 line", L3, 2, STYLE_SOLID, Red);

    }

//---- done
   // Now check for Alert
   
   if (Alerts) DoAlerts();
   
//----
   return(0);
  }
  
//---- Set line labels on chart window
void DisplayLabel(string LabelName, string LabelText, double LabelPos, int LabelFontSize, color LabelColor)
{
      if(ObjectFind(LabelName) != 0)
      {
        ObjectCreate(LabelName, OBJ_TEXT, 0, LabelShiftTime, LabelPos);
        ObjectSetText(LabelName, LabelText, LabelFontSize, "Arial", LabelColor);
      }
      else
      {
        ObjectMove(LabelName, 0, LabelShiftTime, LabelPos);
      }
}

//---  Draw  Pivot lines on chart
void DisplayLine(string LineName, double LinePos, int LineWidth, int LineStyle, color LineColor)
{
      if(ObjectFind(LineName) != 0)
      {
      ObjectCreate(LineName, OBJ_HLINE, 0, LineShiftTime, LinePos);
      ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
      ObjectSet(LineName, OBJPROP_COLOR, LineColor);
      if (LineWidth > 0) ObjectSet(LineName, OBJPROP_WIDTH, LineWidth);
      }
      else
      {
      ObjectMove(LineName, 0, LineShiftTime, LinePos);
      }
}
//+------------------------------------------------------------------+

Recommend