grid_yens3

This script is a technical tool designed for MetaTrader to help traders visualize specific price levels on their trading charts. It focuses on identifying key support and resistance areas based on the weekly opening price of a currency pair.

Core Functionality

The primary goal of this script is to automatically draw a series of horizontal lines across the chart. These lines act as "zones" that can help traders identify where the market might face pressure or potential reversals.

How the Logic Works

1. Data Collection The script begins by looking back at historical price data (specifically 10,080 bars) to identify the opening price of the current week. This specific price point serves as the "Anchor" or "Pivot" for all subsequent calculations.

2. Mathematical Projection Once the weekly opening price is established, the script performs a series of mathematical additions and subtractions:

  • Upper Levels (Resistance): It calculates 8 distinct price levels by adding specific increments (ranging from +8.5 to +12.0) to the weekly opening price.
  • Lower Levels (Support): It simultaneously calculates 8 corresponding lower price levels by subtracting those same increments from the opening price.

3. Visual Representation The script then translates these numbers into visual elements on your screen:

  • Horizontal Lines: It draws solid, medium-blue horizontal lines at every calculated price point. These provide a clear visual guide of the "territories" for the week.
  • Text Labels: To make the chart readable, it places text labels next to these lines. These labels indicate the specific distance from the opening price (e.g., showing how many pips or points the level is above or below the starting point).

User Experience & Behavior

  • Automatic Updates: The script is designed to refresh and redraw these lines constantly, ensuring that as the market moves, the levels remain accurately positioned relative to the weekly data.
  • Clean Environment: The script includes a "cleanup" routine. When you remove or restart the indicator, it automatically deletes all the lines and labels it created, ensuring your chart remains clean and uncluttered.
  • Visual Clarity: By using a consistent color (Medium Blue) and specific labeling, it allows a trader to quickly see the "grid" of expected price zones for the week at a single glance.
12 Views
0 Downloads
0 Favorites
grid_yens3
//+------------------------------------------------------------------+
//|        KlPivot_Weekly_yen.mq4              by Habeeb             |
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

   extern bool Weekly  = True;

   double WeekOpen;
   double WeekLow;
   double WeekClose;
   double Weekly_Price[][6];
   double WeekPivot,WS21,WS22,WS23,WS24,WS25,WS26,WS27,WS28,WR21,WR22,WR23,WR24,WR25,WR26,WR27,WR28;

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

ObjectDelete("WR21_Line");
ObjectDelete("WR22_Line");
ObjectDelete("WR23_Line");
ObjectDelete("WR24_Line");
ObjectDelete("WR25_Line");
ObjectDelete("WR26_Line");
ObjectDelete("WR27_Line");
ObjectDelete("WR28_Line");

ObjectDelete("WS21_Line");
ObjectDelete("WS22_Line");
ObjectDelete("WS23_Line");
ObjectDelete("WS24_Line");
ObjectDelete("WS25_Line");
ObjectDelete("WS26_Line");
ObjectDelete("WS27_Line");
ObjectDelete("WS28_Line"); 

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

ObjectDelete("WR21_Label");
ObjectDelete("WR22_Label");
ObjectDelete("WR23_Label");
ObjectDelete("WR24_Label");
ObjectDelete("WR25_Label");
ObjectDelete("WR26_Label");
ObjectDelete("WR27_Label");
ObjectDelete("WR28_Label");


ObjectDelete("WS21_Label");
ObjectDelete("WS22_Label");
ObjectDelete("WS23_Label");
ObjectDelete("WS24_Label");
ObjectDelete("WS25_Label");
ObjectDelete("WS26_Label");
ObjectDelete("WS27_Label");
ObjectDelete("WS28_Label");

 

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

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

int start()
{
//--------------------------------------------------------
ArrayInitialize(Weekly_Price, 0);
ArrayCopyRates(Weekly_Price, Symbol(), 10080);

WeekOpen  = Weekly_Price[0][1];

WeekPivot = WeekOpen;

      WR21 = WeekPivot + 8.5;
      WS21 = WeekPivot - 8.5;

      WR22 = WeekPivot + 9.0;
      WS22 = WeekPivot - 9.0;

      WS23 = WeekPivot - 9.5;
      WR23 = WeekPivot + 9.5;
      
      WS24 = WeekPivot - 10.0;
      WR24 = WeekPivot + 10.0;
      
      WS25 = WeekPivot - 10.50;
      WR25 = WeekPivot + 10.5;
      
      WS26 = WeekPivot - 11.0;
      WR26 = WeekPivot + 11.0;
      
      WS27 = WeekPivot - 11.50;
      WR27 = WeekPivot + 11.50;
      
      WS28 = WeekPivot - 12.00;
      WR28 = WeekPivot + 12.00;          

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

ObjectsRedraw();

//---------------------------------------------------------
ObjectCreate("WR21_Line", OBJ_HLINE,0, CurTime(),WR21);
ObjectSet("WR21_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR21_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WR21_Label") != 0)
{
ObjectCreate("WR21_Label", OBJ_TEXT, 0, Time[30], WR21);
ObjectSetText("WR21_Label", " +850", 8, "Arial", White);
}
else
{
ObjectMove("WR21_Label", 0, Time[30], WR22);
}

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

ObjectCreate("WR22_Line", OBJ_HLINE,0, CurTime(),WR22);
ObjectSet("WR22_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR22_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR23_Line", OBJ_HLINE,0, CurTime(),WR23);
ObjectSet("WR23_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR23_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR24_Line", OBJ_HLINE,0, CurTime(),WR24);
ObjectSet("WR24_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR24_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WR24_Label") != 0)
{
ObjectCreate("WR24_Label", OBJ_TEXT, 0, Time[30], WR24);
ObjectSetText("WR24_Label", " +1000", 8, "Arial", White);
}
else
{
ObjectMove("WR24_Label", 0, Time[30], WR24);
}
//---------------------------------------------------------

ObjectCreate("WR25_Line", OBJ_HLINE,0, CurTime(),WR25);
ObjectSet("WR25_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR25_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR26_Line", OBJ_HLINE,0, CurTime(),WR26);
ObjectSet("WR26_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR26_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR27_Line", OBJ_HLINE,0, CurTime(),WR27);
ObjectSet("WR27_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR27_Line", OBJPROP_STYLE, STYLE_SOLID);

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


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

ObjectCreate("WR28_Line", OBJ_HLINE,0, CurTime(),WR28);
ObjectSet("WR28_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR28_Line", OBJPROP_STYLE, STYLE_SOLID);

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


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

ObjectCreate("WS21_Line", OBJ_HLINE,0, CurTime(),WS21);
ObjectSet("WS21_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS21_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS21_Label") != 0)
{
ObjectCreate("WS21_Label", OBJ_TEXT, 0, Time[30], WS21);
ObjectSetText("WS21_Label", " -850", 8, "Arial", White);
}
else
{
ObjectMove("WS21_Label", 0, Time[30], WS21);
}

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

ObjectCreate("WS22_Line", OBJ_HLINE,0, CurTime(),WS22);
ObjectSet("WS22_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS22_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS22_Label") != 0)
{
ObjectCreate("WS22_Label", OBJ_TEXT, 0, Time[30], WS22);
ObjectSetText("WS22_Label", " -900", 8, "Arial", White);
}
else
{
ObjectMove("WS22_Label", 0, Time[30], WS22);
}

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

ObjectCreate("WS23_Line", OBJ_HLINE,0, CurTime(),WS23);
ObjectSet("WS23_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS23_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS23_Label") != 0)
{
ObjectCreate("WS23_Label", OBJ_TEXT, 0, Time[30], WS23);
ObjectSetText("WS23_Label", " -950", 8, "Arial", White);
}
else
{
ObjectMove("WS23_Label", 0, Time[30], WS23);
}

//---------------------------------------------------------
ObjectCreate("WS24_Line", OBJ_HLINE,0, CurTime(),WS24);
ObjectSet("WS24_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS24_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS24_Label") != 0)
{
ObjectCreate("WS24_Label", OBJ_TEXT, 0, Time[30], WS24);
ObjectSetText("WS24_Label", " -1000", 8, "Arial", White);
}
else
{
ObjectMove("WS24_Label", 0, Time[30], WS24);
}


//---------------------------------------------------------
//---------------------------------------------------------
ObjectCreate("WS25_Line", OBJ_HLINE,0, CurTime(),WS25);
ObjectSet("WS25_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS25_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS25_Label") != 0)
{
ObjectCreate("WS25_Label", OBJ_TEXT, 0, Time[30], WS25);
ObjectSetText("WS25_Label", " -1050", 8, "Arial", White);
}
else
{
ObjectMove("WS25_Label", 0, Time[30], WS25);
}
//---------------------------------------------------------
ObjectCreate("WS26_Line", OBJ_HLINE,0, CurTime(),WS26);
ObjectSet("WS26_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS26_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS26_Label") != 0)
{
ObjectCreate("WS26_Label", OBJ_TEXT, 0, Time[30], WS26);
ObjectSetText("WS26_Label", " -1100", 8, "Arial", White);
}
else
{
ObjectMove("WS26_Label", 0, Time[30], WS26);
}
//---------------------------------------------------------
ObjectCreate("WS27_Line", OBJ_HLINE,0, CurTime(),WS27);
ObjectSet("WS27_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS27_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS27_Label") != 0)
{
ObjectCreate("WS27_Label", OBJ_TEXT, 0, Time[30], WS27);
ObjectSetText("WS27_Label", " -1150", 8, "Arial", White);
}
else
{
ObjectMove("WS27_Label", 0, Time[30], WS27);
}
//---------------------------------------------------------
ObjectCreate("WS28_Line", OBJ_HLINE,0, CurTime(),WS28);
ObjectSet("WS28_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS28_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS28_Label") != 0)
{
ObjectCreate("WS28_Label", OBJ_TEXT, 0, Time[30], WS28);
ObjectSetText("WS28_Label", " -1200", 8, "Arial", White);
}
else
{
ObjectMove("WS28_Label", 0, Time[30], WS28);

}
}

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


Comments