grid_yens2

This script is designed for the MetaTrader platform to provide visual price guidance based on weekly market data. It identifies key price levels automatically and plots them on your chart, helping traders identify potential support and resistance zones relative to the week's opening price.

Core Logic Overview

The primary purpose of this tool is to calculate a "Pivot" center point based on the opening price of the current week. Once it establishes this baseline, it projects a symmetrical grid of 16 levels—8 above the pivot and 8 below it.

How it Works

  • Data Retrieval: The script scans historical market data to identify the exact opening price of the current week. This price serves as the "Anchor" or "Pivot" for all subsequent calculations.
  • Symmetrical Mapping: From that weekly opening price, the logic calculates specific mathematical offsets. It creates a range of levels expanding outwards:
    • It establishes Resistance levels (WR) by adding specific increments (ranging from 4.5 to 8.0) to the pivot price.
    • It establishes Support levels (WS) by subtracting the corresponding increments from the pivot price.
  • Visual Representation: Once these prices are calculated, the script dynamically draws horizontal lines across your chart. To ensure clarity, it attaches text labels to each line (e.g., "+450", "-500", etc.) so you can immediately see how far a level sits from the weekly starting point.

Key Features for the User

  • Dynamic Updating: The script is designed to refresh and redraw these lines automatically, ensuring that the visual markers stay relevant to the current market environment.
  • Clean Interface: When you remove the indicator from your chart, the script includes a "cleanup" routine that automatically deletes all drawn lines and labels, leaving your workspace tidy.
  • Visual Consistency: All lines are standardized with a specific color (Medium Blue) and style (Solid), providing a clean, professional look for your technical analysis.

In summary, this tool automates the tedious process of manually calculating and drawing support and resistance levels by creating a structured "map" of price targets based on where the week began.

8 Views
0 Downloads
0 Favorites
grid_yens2
//+------------------------------------------------------------------+
//|        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,WS11,WS12,WS13,WS14,WS15,WS16,WS17,WS18,WR11,WR12,WR13,WR14,WR15,WR16,WR17,WR18;

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

ObjectDelete("WR11_Line");
ObjectDelete("WR12_Line");
ObjectDelete("WR13_Line");
ObjectDelete("WR14_Line");
ObjectDelete("WR15_Line");
ObjectDelete("WR16_Line");
ObjectDelete("WR17_Line");
ObjectDelete("WR18_Line");

ObjectDelete("WS11_Line");
ObjectDelete("WS12_Line");
ObjectDelete("WS13_Line");
ObjectDelete("WS14_Line");
ObjectDelete("WS15_Line");
ObjectDelete("WS16_Line");
ObjectDelete("WS17_Line");
ObjectDelete("WS18_Line"); 

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

ObjectDelete("WR11_Label");
ObjectDelete("WR12_Label");
ObjectDelete("WR13_Label");
ObjectDelete("WR14_Label");
ObjectDelete("WR15_Label");
ObjectDelete("WR16_Label");
ObjectDelete("WR17_Label");
ObjectDelete("WR18_Label");


ObjectDelete("WS11_Label");
ObjectDelete("WS12_Label");
ObjectDelete("WS13_Label");
ObjectDelete("WS14_Label");
ObjectDelete("WS15_Label");
ObjectDelete("WS16_Label");
ObjectDelete("WS17_Label");
ObjectDelete("WS18_Label");

 

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

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

int start()
{

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

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

WeekOpen  = Weekly_Price[0][1];

WeekPivot = WeekOpen;

      WR11 = WeekPivot + 4.5;
      WS11 = WeekPivot - 4.5;

      WR12 = WeekPivot + 5.0;
      WS12 = WeekPivot - 5.0;

      WS13 = WeekPivot - 5.5;
      WR13 = WeekPivot + 5.5;
      
      WS14 = WeekPivot - 6.0;
      WR14 = WeekPivot + 6.0;
      
      WS15 = WeekPivot - 6.5;
      WR15 = WeekPivot + 6.5;
      
      WS16 = WeekPivot - 7.0;
      WR16 = WeekPivot + 7.0;
      
      WS17 = WeekPivot - 7.5;
      WR17 = WeekPivot + 7.5;
      
      WS18 = WeekPivot - 8.0;
      WR18 = WeekPivot + 8.0;          

//--------------------------------------------------------
ObjectsRedraw();

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

ObjectCreate("WR11_Line", OBJ_HLINE,0, CurTime(),WR11);
ObjectSet("WR11_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR11_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WR11_Label") != 0)
{
ObjectCreate("WR11_Label", OBJ_TEXT, 0, Time[30], WR11);
ObjectSetText("WR11_Label", " +450", 8, "Arial", White);
}
else
{
ObjectMove("WR1_Label", 0, Time[30], WR11);
}
//--------------------------------------------------------

ObjectCreate("WR12_Line", OBJ_HLINE,0, CurTime(),WR12);
ObjectSet("WR12_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR12_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR13_Line", OBJ_HLINE,0, CurTime(),WR13);
ObjectSet("WR13_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR13_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR14_Line", OBJ_HLINE,0, CurTime(),WR14);
ObjectSet("WR14_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR14_Line", OBJPROP_STYLE, STYLE_SOLID);

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

ObjectCreate("WR15_Line", OBJ_HLINE,0, CurTime(),WR15);
ObjectSet("WR15_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR15_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR16_Line", OBJ_HLINE,0, CurTime(),WR16);
ObjectSet("WR16_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR16_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WR17_Line", OBJ_HLINE,0, CurTime(),WR17);
ObjectSet("WR17_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR17_Line", OBJPROP_STYLE, STYLE_SOLID);

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


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

ObjectCreate("WR18_Line", OBJ_HLINE,0, CurTime(),WR18);
ObjectSet("WR18_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WR18_Line", OBJPROP_STYLE, STYLE_SOLID);

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


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

ObjectCreate("WS11_Line", OBJ_HLINE,0, CurTime(),WS11);
ObjectSet("WS11_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS11_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WS12_Line", OBJ_HLINE,0, CurTime(),WS12);
ObjectSet("WS12_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS12_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

ObjectCreate("WS13_Line", OBJ_HLINE,0, CurTime(),WS13);
ObjectSet("WS13_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS13_Line", OBJPROP_STYLE, STYLE_SOLID);

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

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

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


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

if(ObjectFind("WS15_Label") != 0)
{
ObjectCreate("WS15_Label", OBJ_TEXT, 0, Time[30], WS15);
ObjectSetText("WS15_Label", " -650", 8, "Arial", White);
}
else
{
ObjectMove("WS15_Label", 0, Time[30], WS15);
}
//---------------------------------------------------------
ObjectCreate("WS16_Line", OBJ_HLINE,0, CurTime(),WS16);
ObjectSet("WS16_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS16_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS16_Label") != 0)
{
ObjectCreate("WS16_Label", OBJ_TEXT, 0, Time[30], WS16);
ObjectSetText("WS16_Label", " -700", 8, "Arial", White);
}
else
{
ObjectMove("WS16_Label", 0, Time[30], WS16);
}
//---------------------------------------------------------
ObjectCreate("WS17_Line", OBJ_HLINE,0, CurTime(),WS17);
ObjectSet("WS17_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS17_Line", OBJPROP_STYLE, STYLE_SOLID);

if(ObjectFind("WS17_Label") != 0)
{
ObjectCreate("WS17_Label", OBJ_TEXT, 0, Time[30], WS17);
ObjectSetText("WS17_Label", " -750", 8, "Arial", White);
}
else
{
ObjectMove("WS17_Label", 0, Time[30], WS17);
}
//---------------------------------------------------------
ObjectCreate("WS18_Line", OBJ_HLINE,0, CurTime(),WS18);
ObjectSet("WS18_Line", OBJPROP_COLOR, MediumBlue);
ObjectSet("WS18_Line", OBJPROP_STYLE, STYLE_SOLID);

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

}
}
//----

Comments