grid yens2

This script is designed as a visual navigation tool for traders, providing automated "Pivot Points" on a trading chart. Pivot points are standard technical analysis levels used to identify potential support (where price might stop falling) and resistance (where price might stop rising) based on historical price action.

The logic can be broken down into three main categories:

1. Timeframe Options

The script is designed to handle data across three different timeframes, which the user can toggle in the settings:

  • Daily: Based on the previous day's price movement.
  • Weekly: Based on the current week’s opening price.
  • Monthly: Based on the previous month's high, low, and closing prices.

2. Mathematical Logic

The script calculates different types of levels for each timeframe:

  • Standard Pivot Points (Daily & Monthly): For these timeframes, the script identifies the "Pivot" by taking the average of three values: the High, the Low, and the Closing price of the previous period. From that central pivot, it calculates:

    • Resistance Levels (R1, R2, R3): These represent targets where upward momentum might face difficulty.
    • Support Levels (S1, S2, S3): These represent "floors" where downward momentum might find a buyer.
  • Weekly Custom Levels: The weekly logic functions differently than the daily or monthly ones. Instead of using a standard average of highs and lows, it uses the Week Open price as a fixed center point. It then projects 18 specific levels (9 above and 9 below) based on fixed numerical increments. These are intended to show very specific zones of interest relative to where the week started.

3. Visual Presentation

The script handles all the "heavy lifting" of drawing on your screen so you don't have to do it manually:

  • Automatic Drawing: It automatically creates horizontal lines for every calculated level (Pivots, Supports, and Resistances).
  • Labeling: It places text labels on these lines so you can easily see which line is "Daily R1" or "Monthly S2," etc.
  • Color Coding: The script assigns specific colors to different types of levels (e.g., Red/Maroon for Resistance, Lime Green for Support, and Magenta/Blue for Pivot points) to help with quick visual recognition.
  • Cleanup: When you remove the indicator from your chart, the script includes a "cleanup" function that deletes all the lines and labels it created, leaving your chart clean.
11 Views
0 Downloads
0 Favorites
grid yens2
//+------------------------------------------------------------------+
//|        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,WS11,WS12,WS13,WS14,WS15,WS16,WS17,WS18,WR11,WR12,WR13,WR14,WR15,WR16,WR17,WR18;
   
   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("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");

 

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

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;

      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;          

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

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("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("WR3_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