//+------------------------------------------------------------------+
//| fibopiv weekly.mq4 |
//| Copyright ฉ 2007, MetaQuotes Software Corp. |
//|
http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright ฉ 2007, MetaQuotes Software Corp."
#property link "
http://www.metaquotes.net"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("WS1");
ObjectDelete("WS2");
ObjectDelete("WS3");
ObjectDelete("WR1");
ObjectDelete("WR2");
ObjectDelete("WR3");
ObjectDelete("WEEKLY PIVOT");
ObjectDelete("Weekly Support 1");
ObjectDelete("Weekly 2");
ObjectDelete("Weekly 3");
ObjectDelete("Weekly Pivot level");
ObjectDelete("Weekly Resistance 1");
ObjectDelete("Weekly Resistance 2");
ObjectDelete("Weekly Resistance 3");
Comment(" ");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
double rates[1][6],weekly_close,weekly_high,weekly_low;
ArrayCopyRates(rates, Symbol(), PERIOD_W1);
if(DayOfWeek() == 1)
{
if(TimeDayOfWeek(iTime(Symbol(),PERIOD_W1,1)) == 5)
{
weekly_close = rates[1][4];
weekly_high = rates[1][3];
weekly_low = rates[1][2];
}
else
{
for(int d = 5;d>=0;d--)
{
if(TimeDayOfWeek(iTime(Symbol(),PERIOD_W1,d)) == 5)
{
weekly_close = rates[d][4];
weekly_high = rates[d][3];
weekly_low = rates[d][2];
}
}
}
}
else
{
weekly_close = rates[1][4];
weekly_high = rates[1][3];
weekly_low = rates[1][2];
}
//---- Calculate Pivots
Comment("\nWeekly quotations:\nH ",weekly_high,"\nL ",weekly_low, "\nC ",weekly_close);
double R = weekly_high - weekly_low;//range
double wp = (weekly_high + weekly_low + weekly_close)/3;// Standard Pivot
double wr3 = wp + (R * 1.000);
double wr2 = wp + (R * 0.618);
double wr1 = wp + (R * 0.382);
double ws1 = wp - (R * 0.382);
double ws2 = wp - (R * 0.618);
double ws3 = wp - (R * 1.000);
drawLine(wr3,"WR3", DarkGreen,0);
drawLabel("R 3",wr3,White);
drawLine(wr2,"WR2", DarkGreen,0);
drawLabel("R 2",wr2,White);
drawLine(wr1,"WR1", DarkGreen,0);
drawLabel("R 1",wr1,White);
drawLine(wp,"WEEKLY PIVOT",Goldenrod,1);
drawLabel(" Pivot ",wp,White);
drawLine(ws1,"WS1",DarkSlateBlue,0);
drawLabel("S 1",ws1,White);
drawLine(ws2,"WS2",DarkSlateBlue,0);
drawLabel("S 2",ws2,White);
drawLine(ws3,"WS3",DarkSlateBlue,0);
drawLabel("S 3",ws3,White);
//----
return(0);
}
//+------------------------------------------------------------------+
void drawLabel(string name,double lvl,color Color)
{
if(ObjectFind(name) != 0)
{
ObjectCreate(name, OBJ_TEXT, 0, Time[10], lvl);
ObjectSetText(name, name, 8, "Lucida Handwriting", EMPTY);
ObjectSet(name, OBJPROP_COLOR, Color);
}
else
{
ObjectMove(name, 0, Time[10], lvl);
}
}
void drawLine(double lvl,string name, color Col,int type)
{
if(ObjectFind(name) != 0)
{
ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
if(type == 1)
ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
else
ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
ObjectSet(name, OBJPROP_COLOR, Col);
ObjectSet(name,OBJPROP_WIDTH,1);
}
else
{
ObjectDelete(name);
ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
if(type == 1)
ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
else
ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
ObjectSet(name, OBJPROP_COLOR, Col);
ObjectSet(name,OBJPROP_WIDTH,1);
}
}