grid yens4
Download scriptThis script is an automated charting tool designed for the MetaTrader platform to help traders visualize key price levels. It focuses on "Pivot Points," which are standard technical analysis tools used to identify potential areas of support (where prices might stop falling) and resistance (where prices might stop rising).
The logic of the script can be broken down into three main categories:
1. Timeframe Flexibility
The tool is designed to analyze and display data across different time horizons. While it handles three specific types of calculations, you can toggle which ones are active using the settings:
- Daily: Focuses on price movements from the previous day.
- Weekly: Focuses on price movements over the current week.
- Monthly: Focuses on price movements over the current month.
2. Core Calculation Logic
The script performs three different types of mathematical "snapshots" based on your selection:
- Daily & Monthly Calculations: The tool looks at the previous period's High, Low, and Close prices. It calculates a central "Pivot" (the average of those three) and then derives several Support (S1, S2, S3) and Resistance (R1, R2, R3) levels. These lines help traders see where the market might react based on yesterday's or last month's behavior.
- Weekly Calculations: This logic is unique. It identifies the opening price of the week and creates a wide array of specific "plus" and "minus" levels (ranging from approximately +/- 12.5 to +/- 16.0). These are plotted as distinct horizontal lines to mark significant price boundaries for the week.
3. Visual Display
Rather than just calculating numbers in the background, the script actively modifies your trading chart:
- Dynamic Drawing: It automatically creates horizontal lines on your screen for every level it calculates.
- Color Coding: It uses distinct colors to separate different types of levels (e.g., using variations of Green for Support and Red/Maroon for Resistance) to make the chart easier to read at a glance.
- Labels: It places text labels next to the lines (such as "Daily R1" or "+1500") so you can immediately identify what each line represents without having to guess.
- Auto-Cleanup: The script includes a "deinit" function, which ensures that when you remove the tool from your chart, all the lines and labels are automatically deleted, keeping your workspace clean.
//+------------------------------------------------------------------+
//| KlPivot_Weekly_yen.mq4 by Habeeb |
//| |
//+------------------------------------------------------------------+
#property indicator_chart_window
extern bool Daily = False;
extern bool Weekly = True;
extern bool Monthly = False;
double YesterdayHigh;
double YesterdayLow;
double YesterdayClose;
double Day_Price[][6];
double Pivot,S1,S2,S3,R1,R2,R3;
double WeekOpen;
double WeekLow;
double WeekClose;
double Weekly_Price[][6];
double WeekPivot,WS31,WS32,WS33,WS34,WS35,WS36,WS37,WS38,WR31,WR32,WR33,WR34,WR35,WR36,WR37,WR38;
double MonthHigh;
double MonthLow;
double MonthClose;
double Month_Price[][6];
double MonthPivot,MS1,MS2,MS3,MR1,MR2,MR3;
int init()
{
return(0);
}
//--------------------------------------------------------
int deinit()
{
ObjectDelete("PivotLine");
ObjectDelete("R1_Line");
ObjectDelete("R2_Line");
ObjectDelete("R3_Line");
ObjectDelete("S1_Line");
ObjectDelete("S2_Line");
ObjectDelete("S3_Line");
//--------------------------------
ObjectDelete("PivotLabel");
ObjectDelete("R1_Label");
ObjectDelete("R2_Label");
ObjectDelete("R3_Label");
ObjectDelete("S1_Label");
ObjectDelete("S2_Label");
ObjectDelete("S3_Label");
//--------------------------------------------------------
ObjectDelete("WR31_Line");
ObjectDelete("WR32_Line");
ObjectDelete("WR33_Line");
ObjectDelete("WR34_Line");
ObjectDelete("WR35_Line");
ObjectDelete("WR36_Line");
ObjectDelete("WR37_Line");
ObjectDelete("WR38_Line");
ObjectDelete("WS31_Line");
ObjectDelete("WS32_Line");
ObjectDelete("WS33_Line");
ObjectDelete("WS34_Line");
ObjectDelete("WS35_Line");
ObjectDelete("WS36_Line");
ObjectDelete("WS37_Line");
ObjectDelete("WS38_Line");
//--------------------------------
ObjectDelete("WR31_Label");
ObjectDelete("WR32_Label");
ObjectDelete("WR33_Label");
ObjectDelete("WR34_Label");
ObjectDelete("WR35_Label");
ObjectDelete("WR36_Label");
ObjectDelete("WR37_Label");
ObjectDelete("WR38_Label");
ObjectDelete("WS31_Label");
ObjectDelete("WS32_Label");
ObjectDelete("WS23_Label");
ObjectDelete("WS34_Label");
ObjectDelete("WS35_Label");
ObjectDelete("WS36_Label");
ObjectDelete("WS37_Label");
ObjectDelete("WS38_Label");
//--------------------------------------------------------
ObjectDelete("MonthPivotLine");
ObjectDelete("MR1_Line");
ObjectDelete("MR2_Line");
ObjectDelete("MR3_Line");
ObjectDelete("MS1_Line");
ObjectDelete("MS2_Line");
ObjectDelete("MS3_Line");
//--------------------------------
ObjectDelete("MonthPivotLabel");
ObjectDelete("MR1_Label");
ObjectDelete("MR2_Label");
ObjectDelete("MR3_Label");
ObjectDelete("MS1_Label");
ObjectDelete("MS2_Label");
ObjectDelete("MS3_Label");
return(0);
}
//---------------------------------------------------------
int start()
{
ArrayInitialize(Day_Price,0);
ArrayCopyRates(Day_Price,(Symbol()), 1440);
YesterdayHigh = Day_Price[1][3];
YesterdayLow = Day_Price[1][2];
YesterdayClose = Day_Price[1][4];
Pivot = ((YesterdayHigh + YesterdayLow + YesterdayClose)/3);
R1 = (2*Pivot)-YesterdayLow;
S1 = (2*Pivot)-YesterdayHigh;
R2 = Pivot+(R1-S1);
S2 = Pivot-(R1-S1);
S3 = (YesterdayLow - (2*(YesterdayHigh-Pivot)));
R3 = (YesterdayHigh + (2*(Pivot-YesterdayLow)));
//--------------------------------------------------------
//--------------------------------------------------------
ArrayInitialize(Weekly_Price, 0);
ArrayCopyRates(Weekly_Price, Symbol(), 10080);
WeekOpen = Weekly_Price[0][1];
//WeekLow = Weekly_Price[1][2];
//WeekClose = Weekly_Price[1][4];
WeekPivot = WeekOpen;
WR31 = WeekPivot + 12.5;
WS31 = WeekPivot - 12.5;
WR32 = WeekPivot + 13.0;
WS32 = WeekPivot - 13.0;
WS33 = WeekPivot - 13.5;
WR33 = WeekPivot + 13.5;
WS34 = WeekPivot - 14.0;
WR34 = WeekPivot + 14.0;
WS35 = WeekPivot - 14.50;
WR35 = WeekPivot + 14.5;
WS36 = WeekPivot - 15.0;
WR36 = WeekPivot + 15.0;
WS37 = WeekPivot - 15.50;
WR37 = WeekPivot + 15.50;
WS38 = WeekPivot - 16.00;
WR38 = WeekPivot + 16.00;
//--------------------------------------------------------
//--------------------------------------------------------
ArrayInitialize(Month_Price, 0);
ArrayCopyRates(Month_Price, Symbol(), 43200);
MonthHigh = Month_Price[1][3];
MonthLow = Month_Price[1][2];
MonthClose = Month_Price[1][4];
MonthPivot = ((MonthHigh + MonthLow + MonthClose)/3);
MR1 = (2*MonthPivot)-MonthLow;
MS1 = (2*MonthPivot)-MonthHigh;
MR2 = MonthPivot+(MR1-MS1);
MS2 = MonthPivot-(MR1-MS1);
MS3 = (MonthLow - (2*(MonthHigh-MonthPivot)));
MR3 = (MonthHigh + (2*(MonthPivot-MonthLow)));
//--------------------------------------------------------
if (Daily==true)
{
ObjectCreate("PivotLine", OBJ_HLINE,0, CurTime(),Pivot);
ObjectSet("PivotLine", OBJPROP_COLOR, Magenta);
ObjectSet("PivotLine", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("PivotLabel") != 0)
{
ObjectCreate("PivotLabel", OBJ_TEXT, 0, Time[20], Pivot);
ObjectSetText("PivotLabel", "Daily Pivot", 8, "Arial", Magenta);
}
else
{
ObjectMove("PivotLabel", 0, Time[20], Pivot);
}
//--------------------------------------------------------
ObjectCreate("R1_Line", OBJ_HLINE,0, CurTime(),R1);
ObjectSet("R1_Line", OBJPROP_COLOR, Maroon);
ObjectSet("R1_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("R1_Label") != 0)
{
ObjectCreate("R1_Label", OBJ_TEXT, 0, Time[20], R1);
ObjectSetText("R1_Label", "Daily R1", 8, "Arial", Red);
}
else
{
ObjectMove("R1_Label", 0, Time[20], R1);
}
//--------------------------------------------------------
ObjectCreate("R2_Line", OBJ_HLINE,0, CurTime(),R2);
ObjectSet("R2_Line", OBJPROP_COLOR, Red);
ObjectSet("R2_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("R2_Label") != 0)
{
ObjectCreate("R2_Label", OBJ_TEXT, 0, Time[20], R2);
ObjectSetText("R2_Label", "Daily R2", 8, "Arial", Red);
}
else
{
ObjectMove("R2_Label", 0, Time[20], R2);
}
//---------------------------------------------------------
ObjectCreate("R3_Line", OBJ_HLINE,0, CurTime(),R3);
ObjectSet("R3_Line", OBJPROP_COLOR, Red);
ObjectSet("R3_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("R3_Label") != 0)
{
ObjectCreate("R3_Label", OBJ_TEXT, 0, Time[20], R3);
ObjectSetText("R3_Label", "Daily R3", 8, "Arial", Red);
}
else
{
ObjectMove("R3_Label", 0, Time[20], R3);
}
//---------------------------------------------------------
ObjectCreate("S1_Line", OBJ_HLINE,0, CurTime(),S1);
ObjectSet("S1_Line", OBJPROP_COLOR, LimeGreen);
ObjectSet("S1_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("S1_Label") != 0)
{
ObjectCreate("S1_Label", OBJ_TEXT, 0, Time[20], S1);
ObjectSetText("S1_Label", "Daily S1", 8, "Arial", LimeGreen);
}
else
{
ObjectMove("S1_Label", 0, Time[20], S1);
}
//---------------------------------------------------------
ObjectCreate("S2_Line", OBJ_HLINE,0, CurTime(),S2);
ObjectSet("S2_Line", OBJPROP_COLOR, LimeGreen);
ObjectSet("S2_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("S2_Label") != 0)
{
ObjectCreate("S2_Label", OBJ_TEXT, 0, Time[20], S2);
ObjectSetText("S2_Label", "Daily S2", 8, "Arial", LimeGreen);
}
else
{
ObjectMove("S2_Label", 0, Time[20], S2);
}
//---------------------------------------------------------
ObjectCreate("S3_Line", OBJ_HLINE,0, CurTime(),S3);
ObjectSet("S3_Line", OBJPROP_COLOR, LimeGreen);
ObjectSet("S3_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("S3_Label") != 0)
{
ObjectCreate("S3_Label", OBJ_TEXT, 0, Time[20], S3);
ObjectSetText("S3_Label", "Daily S3", 8, "Arial", LimeGreen);
}
else
{
ObjectMove("S3_Label", 0, Time[20], S3);
}
}
ObjectsRedraw();
//---------------------------------------------------------
//---------------------------------------------------------
//---------------------------------------------------------
//--------------------------------------------------------
ObjectCreate("WR32_Line", OBJ_HLINE,0, CurTime(),WR32);
ObjectSet("WR32_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR32_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WR32_Label") != 0)
{
ObjectCreate("WR32_Label", OBJ_TEXT, 0, Time[30], WR32);
ObjectSetText("WR32_Label", " +1250", 8, "Arial", White);
}
else
{
ObjectMove("WR32_Label", 0, Time[30], WR32);
}
//---------------------------------------------------------
ObjectCreate("WR33_Line", OBJ_HLINE,0, CurTime(),WR33);
ObjectSet("WR33_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR33_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WR33_Line") != 0)
{
ObjectCreate("WR33_Line", OBJ_TEXT, 0, Time[30], WR33);
ObjectSetText("WR33_Line", " +1300", 8, "Arial", White);
}
else
{
ObjectMove("WR33_Line", 0, Time[30], WR33);
}
//---------------------------------------------------------
ObjectCreate("WR34_Line", OBJ_HLINE,0, CurTime(),WR34);
ObjectSet("WR34_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR34_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WR34_Label") != 0)
{
ObjectCreate("WR34_Label", OBJ_TEXT, 0, Time[30], WR34);
ObjectSetText("WR34_Label", " +1350", 8, "Arial", White);
}
else
{
ObjectMove("WR34_Label", 0, Time[30], WR34);
}
//---------------------------------------------------------
ObjectCreate("WR35_Line", OBJ_HLINE,0, CurTime(),WR35);
ObjectSet("WR35_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR35_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WR35_Label") != 0)
{
ObjectCreate("WR35_Label", OBJ_TEXT, 0, Time[30], WR35);
ObjectSetText("WR25_Label", " +1400", 8, "Arial", White);
}
else
{
ObjectMove("WR35_Label", 0, Time[30], WR35);
}
//---------------------------------------------------------
ObjectCreate("WR36_Line", OBJ_HLINE,0, CurTime(),WR36);
ObjectSet("WR36_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR36_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WR36_Label") != 0)
{
ObjectCreate("WR36_Label", OBJ_TEXT, 0, Time[30], WR36);
ObjectSetText("WR36_Label", " +1450", 8, "Arial", White);
}
else
{
ObjectMove("WR36_Label", 0, Time[30], WR36);
}
//---------------------------------------------------------
ObjectCreate("WR37_Line", OBJ_HLINE,0, CurTime(),WR37);
ObjectSet("WR37_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR37_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WR37_Label") != 0)
{
ObjectCreate("WR37_Label", OBJ_TEXT, 0, Time[30], WR37);
ObjectSetText("WR37_Label", " +1500", 8, "Arial", White);
}
else
{
ObjectMove("WR37_Label", 0, Time[30], WR37);
}
//---------------------------------------------------------
ObjectCreate("WR38_Line", OBJ_HLINE,0, CurTime(),WR38);
ObjectSet("WR38_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR38_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WR38_Label") != 0)
{
ObjectCreate("WR38_Label", OBJ_TEXT, 0, Time[30], WR38);
ObjectSetText("W328_Label", " ", +1550, "Arial", White);
}
else
{
ObjectMove("W328_Label", 0, Time[30], WR38);
}
//--------------------------------------------------------
ObjectCreate("WS31_Line", OBJ_HLINE,0, CurTime(),WS31);
ObjectSet("WS31_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS31_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WS31_Label") != 0)
{
ObjectCreate("WS31_Label", OBJ_TEXT, 0, Time[30], WS31);
ObjectSetText("WS31_Label", "-1250", 8, "Arial", White);
}
else
{
ObjectMove("WS31_Label", 0, Time[30], WS31);
}
//---------------------------------------------------------
ObjectCreate("WS32_Line", OBJ_HLINE,0, CurTime(),WS32);
ObjectSet("WS32_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS32_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WS32_Label") != 0)
{
ObjectCreate("WS32_Label", OBJ_TEXT, 0, Time[30], WS32);
ObjectSetText("WS32_Label", " -1300", 8, "Arial", White);
}
else
{
ObjectMove("WS32_Label", 0, Time[30], WS32);
}
//---------------------------------------------------------
ObjectCreate("WS33_Line", OBJ_HLINE,0, CurTime(),WS33);
ObjectSet("WS33_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS33_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WS33_Label") != 0)
{
ObjectCreate("WS33_Label", OBJ_TEXT, 0, Time[30], WS33);
ObjectSetText("WS33_Label", "-1350", 8, "Arial", White);
}
else
{
ObjectMove("WS33_Label", 0, Time[30], WS33);
}
//---------------------------------------------------------
ObjectCreate("WS34_Line", OBJ_HLINE,0, CurTime(),WS34);
ObjectSet("WS34_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS34_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WS34_Label") != 0)
{
ObjectCreate("WS34_Label", OBJ_TEXT, 0, Time[30], WS34);
ObjectSetText("WS34_Label", "-1400", 8, "Arial", White);
}
else
{
ObjectMove("WS34_Label", 0, Time[30], WS34);
}
//---------------------------------------------------------
//---------------------------------------------------------
ObjectCreate("WS35_Line", OBJ_HLINE,0, CurTime(),WS35);
ObjectSet("WS35_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS35_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WS35_Label") != 0)
{
ObjectCreate("WS35_Label", OBJ_TEXT, 0, Time[30], WS35);
ObjectSetText("WS35_Label", "-1450", 8, "Arial", White);
}
else
{
ObjectMove("WS35_Label", 0, Time[30], WS35);
}
//---------------------------------------------------------
ObjectCreate("WS36_Line", OBJ_HLINE,0, CurTime(),WS36);
ObjectSet("WS36_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS36_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WS36_Label") != 0)
{
ObjectCreate("WS36_Label", OBJ_TEXT, 0, Time[30], WS36);
ObjectSetText("WS36_Label", "-1500", 8, "Arial", White);
}
else
{
ObjectMove("WS36_Label", 0, Time[30], WS36);
}
//---------------------------------------------------------
ObjectCreate("WS37_Line", OBJ_HLINE,0, CurTime(),WS37);
ObjectSet("WS37_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS37_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WS37_Label") != 0)
{
ObjectCreate("WS27_Label", OBJ_TEXT, 0, Time[30], WS37);
ObjectSetText("WS27_Label", " -1550", 8, "Arial", White);
}
else
{
ObjectMove("WS37_Label", 0, Time[30], WS37);
}
//---------------------------------------------------------
ObjectCreate("WS28_Line", OBJ_HLINE,0, CurTime(),WS38);
ObjectSet("WS38_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS38_Line", OBJPROP_STYLE, STYLE_SOLID);
if(ObjectFind("WS38_Label") != 0)
{
ObjectCreate("WS38_Label", OBJ_TEXT, 0, Time[30], WS38);
ObjectSetText("WS38_Label", " -1600", 8, "Arial", White);
}
else
{
ObjectMove("WS38_Label", 0, Time[30], WS38);
}
}
//---------------------------------------------------------
Comments