grid_yens

This script is designed as a visual charting tool for traders using the MetaTrader platform. Its primary purpose is to automatically identify and plot specific price levels based on the weekly market opening, helping traders visualize potential support and resistance zones.

Core Functionality

The logic of the script can be broken down into three main stages:

1. Data Retrieval The tool begins by scanning historical price data to locate the opening price of the current week. It looks back through a significant amount of historical data to ensure it captures the correct starting point for the weekly cycle.

2. Mathematical Calculation Once the "Weekly Open" price is identified, the script uses it as an anchor point (the baseline). From this baseline, it calculates a series of symmetrical price levels:

  • Resistance Levels (WR): These are calculated by adding specific increments to the weekly open (e.g., +50, +100, +150, up to +400).
  • Support Levels (WS): These are calculated by subtracting the same increments from the weekly open (e.g., -50, -100, -150, down to -400).

3. Visual Representation The script then draws these calculated levels directly onto your trading chart as horizontal lines. To make the chart easy to read:

  • Color Coding: It uses distinct colors (such as Aqua for the main weekly open and Medium Blue for the subsequent levels) so traders can instantly distinguish between different price zones.
  • Labeling: It places text labels next to each line (e.g., "+50", "-100") so you can see exactly how far each level sits from the opening price without having to manually calculate the distance.

Summary for the User

Essentially, this script automates the "math" of setting up a grid based on the week's start. Instead of you having to manually calculate and draw 16 different lines every time the week changes, the script detects the weekly open and automatically paints a balanced map of support and resistance levels across your screen.

8 Views
0 Downloads
0 Favorites
grid_yens
//+------------------------------------------------------------------+
//|        KlPivot_Weekly_yen.mq4              by Habeeb             |
//|        butchered by fxbs 4 spirit                                |
//+------------------------------------------------------------------+

#property indicator_chart_window

   extern bool Weekly  = True;
   double WeekOpen;
   double Weekly_Price[][6];
   double WeekPivot,WS1,WS2,WS3,WS4,WS5,WS6,WS7,WS8,WR1,WR2,WR3,WR4,WR5,WR6,WR7,WR8;
   
int init()
  {
   return(0);
  }
//-------------------------------------------------------- 
int deinit()
  {
//--------------------------------------------------------

ObjectDelete("WeekPivotLine");

ObjectDelete("WR1_Line");
ObjectDelete("WR2_Line");
ObjectDelete("WR3_Line");
ObjectDelete("WR4_Line");
ObjectDelete("WR5_Line");
ObjectDelete("WR6_Line");
ObjectDelete("WR7_Line");
ObjectDelete("WR8_Line");

ObjectDelete("WS1_Line");
ObjectDelete("WS2_Line");
ObjectDelete("WS3_Line");
ObjectDelete("WS4_Line");
ObjectDelete("WS5_Line");
ObjectDelete("WS6_Line");
ObjectDelete("WS7_Line");
ObjectDelete("WS8_Line"); 

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

ObjectDelete("WeekPivotLabel");

ObjectDelete("WR1_Label");
ObjectDelete("WR2_Label");
ObjectDelete("WR3_Label");
ObjectDelete("WR4_Label");
ObjectDelete("WR5_Label");
ObjectDelete("WR6_Label");
ObjectDelete("WR7_Label");
ObjectDelete("WR8_Label");

ObjectDelete("WS1_Label");
ObjectDelete("WS2_Label");
ObjectDelete("WS3_Label");
ObjectDelete("WS4_Label");
ObjectDelete("WS5_Label"); 
ObjectDelete("WS6_Label");
ObjectDelete("WS7_Label");
ObjectDelete("WS8_Label");
//--------------------------------------------------------
return(0);
}
//--------------------------------------------------------- 

int start()
{
//--------------------------------------------------------

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

WeekOpen  = Weekly_Price[0][1];

WeekPivot = WeekOpen;

      WR1 = WeekPivot + 0.5;
      WS1 = WeekPivot - 0.5;

      WR2 = WeekPivot + 1.0;
      WS2 = WeekPivot - 1.0;

      WS3 = WeekPivot - 1.5;
      WR3 = WeekPivot + 1.5;
      
      WS4 = WeekPivot - 2.0;
      WR4 = WeekPivot + 2.0;
      
      WS5 = WeekPivot - 2.5;
      WR5 = WeekPivot + 2.5;
      
      WS6 = WeekPivot - 3.0;
      WR6 = WeekPivot + 3.0;
      
      WS7 = WeekPivot - 3.5;
      WR7 = WeekPivot + 3.5;
      
      WS8 = WeekPivot - 4.0;
      WR8 = WeekPivot + 4.0;          

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

if (Weekly==true)
{
ObjectCreate("WeekPivotLine", OBJ_HLINE,0, CurTime(),WeekPivot);
ObjectSet("WeekPivotLine", OBJPROP_COLOR, Aqua);
ObjectSet("WeekPivotLine", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WeekPivotLabel") != 0)
{
ObjectCreate("WeekPivotLabel", OBJ_TEXT, 0, Time[30], WeekPivot);
ObjectSetText("WeekPivotLabel", "Weekly Open 00", 8, "Arial", Aqua);
}
else
{
ObjectMove("WeekPivotLabel", 0, Time[30], WeekPivot);
}

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

ObjectCreate("WR1_Line", OBJ_HLINE,0, CurTime(),WR1);
ObjectSet("WR1_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR1_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR2_Line", OBJ_HLINE,0, CurTime(),WR2);
ObjectSet("WR2_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR2_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR3_Line", OBJ_HLINE,0, CurTime(),WR3);
ObjectSet("WR3_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR3_Line", OBJPROP_STYLE, STYLE_SOLID);

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

ObjectCreate("WR4_Line", OBJ_HLINE,0, CurTime(),WR4);
ObjectSet("WR4_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR4_Line", OBJPROP_STYLE, STYLE_SOLID);

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

ObjectCreate("WR5_Line", OBJ_HLINE,0, CurTime(),WR5);
ObjectSet("WR5_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR5_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR6_Line", OBJ_HLINE,0, CurTime(),WR6);
ObjectSet("WR6_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR6_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR7_Line", OBJ_HLINE,0, CurTime(),WR7);
ObjectSet("WR7_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR7_Line", OBJPROP_STYLE, STYLE_SOLID);

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

ObjectCreate("WR8_Line", OBJ_HLINE,0, CurTime(),WR8);
ObjectSet("WR8_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR8_Line", OBJPROP_STYLE, STYLE_SOLID);

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

ObjectCreate("WS1_Line", OBJ_HLINE,0, CurTime(),WS1);
ObjectSet("WS1_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS1_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WS2_Line", OBJ_HLINE,0, CurTime(),WS2);
ObjectSet("WS2_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS2_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WS3_Line", OBJ_HLINE,0, CurTime(),WS3);
ObjectSet("WS3_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS3_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS3_Label") != 0)
{
ObjectCreate("WS3_Label", OBJ_TEXT, 0, Time[30], WS3);
ObjectSetText("WS3_Label", " -150", 8, "Arial", White);
}
else
{
ObjectMove("WS3_Label", 0, Time[30], WS3);
}
//---------------------------------------------------------
ObjectCreate("WS4_Line", OBJ_HLINE,0, CurTime(),WS4);
ObjectSet("WS4_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS4_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS4_Label") != 0)
{
ObjectCreate("WS4_Label", OBJ_TEXT, 0, Time[30], WS4);
ObjectSetText("WS4_Label", " -200", 8, "Arial", White);
}
else
{
ObjectMove("WS4_Label", 0, Time[30], WS4);
}
//---------------------------------------------------------
ObjectCreate("WS5_Line", OBJ_HLINE,0, CurTime(),WS5);
ObjectSet("WS5_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS5_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS5_Label") != 0)
{
ObjectCreate("WS5_Label", OBJ_TEXT, 0, Time[30], WS5);
ObjectSetText("WS5_Label", " -250", 8, "Arial", White);
}
else
{
ObjectMove("WS5_Label", 0, Time[30], WS5);
}
//---------------------------------------------------------
ObjectCreate("WS6_Line", OBJ_HLINE,0, CurTime(),WS6);
ObjectSet("WS6_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS6_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS6_Label") != 0)
{
ObjectCreate("WS6_Label", OBJ_TEXT, 0, Time[30], WS6);
ObjectSetText("WS6_Label", " -300", 8, "Arial", White);
}
else
{
ObjectMove("WS6_Label", 0, Time[30], WS6);
}
//---------------------------------------------------------
ObjectCreate("WS7_Line", OBJ_HLINE,0, CurTime(),WS7);
ObjectSet("WS7_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS7_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS7_Label") != 0)
{
ObjectCreate("WS7_Label", OBJ_TEXT, 0, Time[30], WS7);
ObjectSetText("WS7_Label", " -350", 8, "Arial", White);
}
else
{
ObjectMove("WS7_Label", 0, Time[30], WS7);
}
//---------------------------------------------------------
ObjectCreate("WS8_Line", OBJ_HLINE,0, CurTime(),WS8);
ObjectSet("WS8_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS8_Line", OBJPROP_STYLE, STYLE_SOLID);

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

}
}


ObjectsRedraw();

   return(0);
}

Comments