//+------------------------------------------------------------------+
//| Floor_Pivots_Daily.mq4 |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 C'000,200,000'
#property indicator_color2 C'000,200,000'
#property indicator_color3 C'000,200,000'
#property indicator_color4 C'200,200,200'
#property indicator_color5 C'200,000,000'
#property indicator_color6 C'200,000,000'
#property indicator_color7 C'200,000,000'
extern string PivotStart = "22:00";
extern string PivotEnd = "22:00";
double Buffer1[];
double Buffer2[];
double Buffer3[];
double Buffer4[];
double Buffer5[];
double Buffer6[];
double Buffer7[];
double LastHigh,LastLow,LastClose;
double PivR3,PivR2,PivR1, PivotPoint, PivS1,PivS2,PivS3;
int OpenBar;
int init()
{ SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,160);
SetIndexBuffer(0,Buffer1);
SetIndexLabel(0,"Pivot R3");
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,160);
SetIndexBuffer(1,Buffer2);
SetIndexLabel(1,"Pivot R2");
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,160);
SetIndexBuffer(2,Buffer3);
SetIndexLabel(2,"Pivot R1");
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,167);
SetIndexBuffer(3,Buffer4);
SetIndexLabel(3,"Pivot Point");
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,160);
SetIndexBuffer(4,Buffer5);
SetIndexLabel(4,"Pivot S1");
SetIndexStyle(5,DRAW_ARROW);
SetIndexArrow(5,160);
SetIndexBuffer(5,Buffer6);
SetIndexLabel(5,"Pivot S2");
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,160);
SetIndexBuffer(6,Buffer7);
SetIndexLabel(6,"Pivot S3");
return(0); }
int deinit()
{
ObjectDelete("R3L");
ObjectDelete("R2L");
ObjectDelete("R1L");
ObjectDelete("PPL");
ObjectDelete("S1L");
ObjectDelete("S2L");
ObjectDelete("S3L");
Comment("");
return(0);
}
int start()
{ if (Period() > 240) return(0); //Chart cannot be higher than H4
string BarTime="", LastBarTime="";
string BarDay="", LastBarDay="";
int CloseBar;
for(int i=Bars; i>=0; i--)
{ BarTime = TimeToStr(Time[i], TIME_MINUTES);
LastBarTime = TimeToStr(Time[i+1], TIME_MINUTES);
BarDay = TimeToStr(Time[i],TIME_DATE);
LastBarDay = TimeToStr(Time[i+1],TIME_DATE);
//need to handle if pivotrangestart/end is 00:00
if ((PivotEnd == "00:00" && BarTime>=PivotEnd && BarDay>LastBarDay) || (BarTime>=PivotEnd && LastBarTime<PivotEnd))
{ CloseBar = i + 1;
if (OpenBar>0)
{ calculatePivotRangeValues(OpenBar, CloseBar); } }
if ((PivotStart == "00:00" && BarTime>=PivotStart && BarDay>LastBarDay) || (BarTime>=PivotStart && LastBarTime<PivotStart))
{ OpenBar = i; }
if (OpenBar>0)
{ drawIndicators(i); } }
return(0);}
void calculatePivotRangeValues(int openBar, int closeBar)
{
LastHigh = High[Highest(NULL, 0, MODE_HIGH, (openBar - closeBar + 1), closeBar)];
LastLow = Low[Lowest(NULL, 0, MODE_LOW, (openBar - closeBar + 1), closeBar)];
LastClose = Close[closeBar];
PivotPoint = (LastHigh + LastLow + LastClose)/3;
PivR3 = (2*PivotPoint)+(LastHigh-(2*LastLow));
PivR2 = PivotPoint+(LastHigh - LastLow);
PivR1 = (2*PivotPoint)-LastLow;
PivS1 = (2*PivotPoint)-LastHigh;
PivS2 = PivotPoint-(LastHigh - LastLow);
PivS3 = (2*PivotPoint)-((2* LastHigh)-LastLow);
}
void drawIndicators(int curBar)
{
Buffer1[curBar]=PivR3;
Buffer2[curBar]=PivR2;
Buffer3[curBar]=PivR1;
Buffer4[curBar]=PivotPoint;
Buffer5[curBar]=PivS1;
Buffer6[curBar]=PivS2;
Buffer7[curBar]=PivS3;
DoLabel("R3L", Buffer1[0], indicator_color1);
DoLabel("R2L", Buffer2[0], indicator_color2);
DoLabel("R1L", Buffer3[0], indicator_color3);
DoLabel("PPL", Buffer4[0], indicator_color4);
DoLabel("S1L", Buffer5[0], indicator_color5);
DoLabel("S2L", Buffer6[0], indicator_color6);
DoLabel("S3L", Buffer7[0], indicator_color7);
return(0); }
void DoLabel( string dName, double dValue, color dColor )
{
if (ObjectFind(dName) != 0)
{
ObjectCreate(dName,OBJ_ARROW,0,Time[0],dValue);
ObjectSet(dName,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
ObjectSet(dName,OBJPROP_COLOR,dColor);
}
else
{
ObjectMove(dName,0,Time[0],dValue);
}
}
//+-----------------------------------------------------------------------------------------+
//| THE END |
//+-----------------------------------------------------------------------------------------+
Comments