grid_yens4

This script is a specialized trading tool designed for the MetaTrader platform to help traders visualize specific price levels based on weekly market data. It primarily functions as an automated drawing tool that identifies and plots horizontal reference lines on a chart.

Core Functionality

The primary purpose of this script is to calculate and display a series of "Pivot" points based on the opening price of the current week. Instead of using complex moving averages or lagging indicators, it uses a fixed mathematical offset from the weekly opening price to establish support and resistance zones.

How the Logic Works

The script follows a structured three-step process:

1. Data Retrieval The tool begins by scanning historical price data for the current symbol. It specifically looks back far enough to locate the beginning of the week to identify the "Week Open" price. This opening price serves as the anchor or "base" for all subsequent calculations.

2. Calculation of Support and Resistance Levels Once the weekly opening price is identified, the script calculates 16 distinct horizontal levels divided into two categories:

  • Resistance Levels (WR): These are calculated by adding specific increments (ranging from 12.5 to 16.0) to the weekly opening price. These represent potential "ceiling" areas where price might face selling pressure.
  • Support Levels (WS): These are calculated by subtracting corresponding increments from the weekly opening price. These represent potential "floor" areas where price might find buying interest.

3. Visual Mapping After calculating these 16 prices, the script automatically draws them on your trading chart as solid horizontal lines. To ensure the chart remains readable:

  • Color Coding: All lines are rendered in a consistent Medium Blue color.
  • Labeling: The script places a text label next to each line (e.g., "+1250", "-1300") to clearly indicate the specific offset from the weekly open.
  • Dynamic Cleanup: The script includes a "cleanup" routine that ensures old lines and labels are removed when the indicator is turned off, keeping your workspace tidy.

Summary for the User

In essence, this tool automates the manual task of calculating weekly price targets. By identifying where the week started, it instantly maps out a corridor of potential price action, allowing you to see at a glance where key support and resistance zones are located based on the current week's geometry.

10 Views
0 Downloads
0 Favorites
grid_yens4
//+------------------------------------------------------------------+
//|        KlPivot_Weekly_yen.mq4              by Habeeb             |
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

   extern bool Weekly  = True;

   double YesterdayHigh;
   double YesterdayLow;
   double YesterdayClose;
   double Day_Price[][6];
   double Pivot;
   
   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;
   

int init()
  {
   return(0);
  }
 
//-------------------------------------------------------- 
 
int deinit()
  {

//--------------------------------------------------------

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("WS33_Label");
ObjectDelete("WS34_Label");
ObjectDelete("WS35_Label");
ObjectDelete("WS36_Label");
ObjectDelete("WS37_Label");
ObjectDelete("WS38_Label");
 

//--------------------------------------------------------

//
return(0);
}
//--------------------------------------------------------- 

int start()
{


//--------------------------------------------------------

ArrayInitialize(Weekly_Price, 0);
ArrayCopyRates(Weekly_Price, Symbol(), 10080);

WeekOpen  = Weekly_Price[0][1];

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;          


//--------------------------------------------------------
//--------------------------------------------------------

ObjectsRedraw();

//---------------------------------------------------------

ObjectCreate("WR31_Line", OBJ_HLINE,0, CurTime(),WR31);
ObjectSet("WR31_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR31_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WR31_Label") != 0)
{
ObjectCreate("WR31_Label", OBJ_TEXT, 0, Time[30], WR31);
ObjectSetText("WR31_Label", " +1250", 8, "Arial", White);
}
else
{
ObjectMove("WR31_Label", 0, Time[30], WR31);
}


//--------------------------------------------------------

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", " +1300", 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_Label") != 0)
{
ObjectCreate("WR33_Label", OBJ_TEXT, 0, Time[30], WR33);
ObjectSetText("WR33_Label", " +1350", 8, "Arial", White);
}
else
{
ObjectMove("WR33_Label", 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", " +1400", 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("WR35_Label", " +1450", 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", " +1500", 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", " +1550", 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("WR38_Label", " +1600", 8, "Arial", White);
}
else
{
ObjectMove("WR38_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("WS37_Label", OBJ_TEXT, 0, Time[30], WS37);
ObjectSetText("WS37_Label", " -1550", 8, "Arial", White);
}
else
{
ObjectMove("WS37_Label", 0, Time[30], WS37);
}
//---------------------------------------------------------
ObjectCreate("WS38_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