Pivots_Monthly
Download scriptThis script is a specialized financial analysis tool designed to automatically identify and display key price levels on your trading charts. It focuses specifically on Monthly Pivot Points and their associated support and resistance levels, which are crucial markers for traders looking to understand broader market structure.
Core Functionality
The primary objective of this script is to calculate "Pivot Points"—mathematical averages used to determine the equilibrium of a market price. Because markets can be volatile, these points help traders identify where the price might stall, reverse, or break out.
Specifically, this tool calculates seven distinct levels based on the price action of the previous month:
- The Monthly Pivot Point: The central "anchor" or balance point for the current month.
- Support Levels (S1, S2, S3): These represent potential "floors." They are prices where buying interest is expected to increase, potentially stopping a downward move.
- Resistance Levels (R1, R2, R3): These represent potential "ceilings." They are prices where selling pressure typically builds, potentially halting an upward move.
How the Logic Works
The script follows a systematic process to ensure the data remains accurate regardless of your broker's specific time settings:
- Time Synchronization: The tool is designed to be "broker-independent." It uses logic that ensures it correctly identifies the transition between months, specifically accounting for Monday openings to keep the levels consistent across different global time zones.
- Data Gathering: At the start of a new month, the script looks back at the high, low, and closing prices of the entire preceding month.
- Mathematical Projection: It uses these three historical figures to project the pivots for the current period. For example, it calculates the central Pivot by averaging the previous month's high, low, and close. It then uses that center point to mathematically derive the three support and three resistance levels.
- Dynamic Visual Mapping: As the market moves, the script continuously tracks the highest and lowest prices reached during the current month. It updates these values in real-time so that the displayed labels stay current with the evolving price action.
- On-Chart Labeling: Unlike basic indicators that might just draw lines, this script places clear, readable text labels directly on your chart. This allows you to see the exact numerical value of each Support (Mo S) and Resistance (Mo R) level at a glance, along with their specific colors for easy identification.
Key Features for the User
- High Visibility: Each level is assigned a unique color (such as Violet for support and Salmon for resistance) to help you distinguish between different types of price barriers quickly.
- Automated Precision: By automating these calculations, the script removes the risk of human error in manual math, providing consistent levels based on standard institutional trading formulas.
- Clean Chart Interface: The script is designed to handle its own "cleanup," ensuring that labels are correctly positioned and updated without cluttering your workspace.
//+------------------------------------------------------------------+
//| WeeklyPivot.mq4 |
//| I found the original indicator in TSD forum posted by heliyaun. |
//| I don´t know how wrote it. |
//| I like it because have mondays fixed for broker with GMT outside |
//| london time. |
//| So, I added some stuff, labels, fix, etc. and them, I wrote the|
//| Medians SR, and then, I wrote the same for Monthlies |
//| |
//| Enjoy. |
//| |
//| Linuxser, January 2007 |
//| |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Brown
#property indicator_color2 Salmon
#property indicator_color3 MediumOrchid
#property indicator_color4 HotPink
#property indicator_color5 MediumPurple
#property indicator_color6 Violet
#property indicator_color7 Orchid
//---- input parameters
extern color SupportLabelColor=Violet;
extern color ResistanceLabelColor=Salmon;
extern color PivotLabelColor=Brown;
extern int fontsize=10;
extern int LabelShift = 0;
//---- buffers
double MPBuffer[];
double MS1Buffer[];
double MR1Buffer[];
double MS2Buffer[];
double MR2Buffer[];
double MS3Buffer[];
double MR3Buffer[];
string Pivot="MonthlyPivotPoint",Sup1="M_S 1", Res1="M_R 1";
string Sup2="M_S 2", Res2="M_R 2", Sup3="M_S 3", Res3="M_R 3";
double MP,MS1,MR1,MS2,MR2,MS3,MR3;
double last_month_high, last_month_low, this_month_open, last_month_close;
datetime LabelShiftTime;
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
ObjectDelete("monthlyPivot");
ObjectDelete("MSup1");
ObjectDelete("MRes1");
ObjectDelete("MSup2");
ObjectDelete("MRes2");
ObjectDelete("MSup3");
ObjectDelete("MRes3");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE,EMPTY);
SetIndexStyle(1,DRAW_LINE,EMPTY);
SetIndexStyle(2,DRAW_LINE,EMPTY);
SetIndexStyle(3,DRAW_LINE,EMPTY);
SetIndexStyle(4,DRAW_LINE,EMPTY);
SetIndexStyle(5,DRAW_LINE,EMPTY);
SetIndexStyle(6,DRAW_LINE,EMPTY);
SetIndexBuffer(0,MPBuffer);
SetIndexBuffer(1,MS1Buffer);
SetIndexBuffer(2,MR1Buffer);
SetIndexBuffer(3,MS2Buffer);
SetIndexBuffer(4,MR2Buffer);
SetIndexBuffer(5,MS3Buffer);
SetIndexBuffer(6,MR3Buffer);
//---- name for DataWindow and indicator subwindow label
short_name="Pivot Point Monthly";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,1);
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit, i;
//---- indicator calculation
if (counted_bars==0)
{
if(Period() > 1440)
{
Print("Error - Chart period is greater than 1 day.");
return(-1); // then exit
}
}
if(counted_bars<0) return(-1);
limit=(Bars-counted_bars)-1;
for (i=limit; i>=0;i--)
{
// Monday
if(TimeDay(Time[i])<=3 && TimeDay(Time[i+1])>=26)
{
last_month_close = Close[i+1];
this_month_open = Open[i];
// monthlyPivot
MP = (last_month_high + last_month_low + last_month_close) / 3;
MR1 = (2*MP)-last_month_low;
MS1 = (2*MP)-last_month_high;
MR2 = MP+(last_month_high - last_month_low);
MS2 = MP-(last_month_high - last_month_low);
MR3 = (2*MP)+(last_month_high-(2*last_month_low));
MS3 = (2*MP)-((2* last_month_high)-last_month_low);
last_month_low=Low[i]; last_month_high=High[i];
LabelShiftTime = Time[LabelShift];
ObjectCreate("MonthlyPivot", OBJ_TEXT, 0,LabelShiftTime,0);
ObjectSetText("MonthlyPivot", " Monthly Pivot Point "+DoubleToStr(MP,4),fontsize,"Arial",PivotLabelColor);
SetIndexLabel(0, "Monthly Pivot Point");
ObjectCreate("MSup1", OBJ_TEXT, 0, LabelShiftTime, 0);
ObjectSetText("MSup1", " Mo S1 "+DoubleToStr(MS1,4),fontsize,"Arial",SupportLabelColor);
SetIndexLabel(1, "MSup1");
ObjectCreate("MRes1", OBJ_TEXT, 0, LabelShiftTime, 0);
ObjectSetText("MRes1", " Mo R1 "+DoubleToStr(MR1,4),fontsize,"Arial",ResistanceLabelColor);
SetIndexLabel(2, "MRes1");
ObjectCreate("MSup2", OBJ_TEXT, 0, LabelShiftTime, 0);
ObjectSetText("MSup2", " Mo S2 "+DoubleToStr(MS2,4),fontsize,"Arial",SupportLabelColor);
SetIndexLabel(3, "MSup2");
ObjectCreate("MRes2", OBJ_TEXT, 0, LabelShiftTime, 0);
ObjectSetText("MRes2", " Mo R2 "+DoubleToStr(MR2,4),fontsize,"Arial",ResistanceLabelColor);
SetIndexLabel(4, "MRes2");
ObjectCreate("MSup3", OBJ_TEXT, 0, LabelShiftTime, 0);
ObjectSetText("MSup3", " Mo S3 "+DoubleToStr(MS3,4),fontsize,"Arial",SupportLabelColor);
SetIndexLabel(5, "MSup3");
ObjectCreate("MRes3", OBJ_TEXT, 0, LabelShiftTime, 0);
ObjectSetText("MRes3", " Mo R3 "+DoubleToStr(MR3,4),fontsize,"Arial",ResistanceLabelColor);
SetIndexLabel(6, "MRes3");
ObjectMove("MonthlyPivot", 0, LabelShiftTime,MP);
ObjectMove("MSup1", 0, LabelShiftTime,MS1);
ObjectMove("MRes1", 0, LabelShiftTime,MR1);
ObjectMove("MSup2", 0, LabelShiftTime,MS2);
ObjectMove("MRes2", 0, LabelShiftTime,MR2);
ObjectMove("MSup3", 0, LabelShiftTime,MS3);
ObjectMove("MRes3", 0, LabelShiftTime,MR3);
}
last_month_high = MathMax(last_month_high, High[i]);
last_month_low = MathMin(last_month_low, Low[i]);
MPBuffer[i]=MP;
MS1Buffer[i]=MS1;
MR1Buffer[i]=MR1;
MS2Buffer[i]=MS2;
MR2Buffer[i]=MR2;
MS3Buffer[i]=MS3;
MR3Buffer[i]=MR3;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments