YearlyPivot-mids
Download scriptThis script is designed to provide traders with clear, visual price benchmarks based on annual market movements. It automatically calculates and displays "Yearly Pivot Points" along with several Support and Resistance levels directly on your trading chart.
Core Logic Overview
The primary objective of this tool is to identify significant price zones that occur on a yearly basis. Instead of using short-term fluctuations, it looks at the broader historical context of the previous year to determine where "heavy" buying or selling pressure might occur in the current year.
How It Works
The script follows a specific logical flow to generate these levels:
1. Data Collection The tool constantly monitors the market's highs, lows, and closing prices. It specifically looks for the transition period between the end of one year and the beginning of the next.
2. Pivot Point Calculation When the script detects a new year starting (specifically during the first 10 days of January), it takes the data from the preceding year—including its highest point, lowest point, and final closing price—and combines it with the opening price of the current year. It uses these figures to calculate:
- The Yearly Pivot Point: The central "balance" price for the year.
- Support Levels (S1, S2, S3): These represent price floors where the market may find enough buying interest to stop a downward trend.
- Resistance Levels (R1, R2, R3): These represent price ceilings where the market may face enough selling pressure to stall an upward move.
3. Dynamic Updates As the script moves through the historical data on your chart:
- It identifies the highest and lowest points reached during the year to refine its calculations.
- It updates the positions of these levels automatically so that they remain accurate relative to the timeframe you are viewing.
User Experience & Constraints
- Visual Clarity: The script places labeled lines on your chart, making it easy to see at a glance where the major yearly benchmarks sit.
- Timeframe Compatibility: To ensure accuracy and maintain a clean visual layout, this tool is designed to be used on higher timeframes (Weekly or Monthly charts). It will not display correctly on very small, short-term charts like 1-minute or 5-minute intervals.
- Automation: Once added to a chart, the logic handles all the heavy lifting—calculating the math and drawing the lines—so you can focus on analyzing price action relative to these key levels.
//+------------------------------------------------------------------+
//| Yearly Pivot |
//| Copyright © 2006, Profitrader |
//| Coded/Verified by Profitrader |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Profitrader."
#property link "profitrader@inbox.ru"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Black
#property indicator_color2 White
#property indicator_color3 White
#property indicator_color4 White
#property indicator_color5 White
#property indicator_color6 White
#property indicator_color7 White
//---- buffers
double PBuffer[];
double S1Buffer[];
double R1Buffer[];
double S2Buffer[];
double R2Buffer[];
double S3Buffer[];
double R3Buffer[];
double P,S1,R1,S2,R2,S3,R3,last_year_high,last_year_low,last_year_close,this_year_open;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
SetIndexBuffer(0,PBuffer);
SetIndexBuffer(1,S1Buffer);
SetIndexBuffer(2,R1Buffer);
SetIndexBuffer(3,S2Buffer);
SetIndexBuffer(4,R2Buffer);
SetIndexBuffer(5,S3Buffer);
SetIndexBuffer(6,R3Buffer);
SetIndexStyle(0,DRAW_LINE,0,2);
SetIndexStyle(1,DRAW_LINE,4,1);
SetIndexStyle(2,DRAW_LINE,4,1);
SetIndexStyle(3,DRAW_LINE,4,1);
SetIndexStyle(4,DRAW_LINE,4,1);
SetIndexStyle(5,DRAW_LINE,4,1);
SetIndexStyle(6,DRAW_LINE,4,1);
SetIndexLabel(0,"Yearly Pivot Point");
SetIndexLabel(1,"Yearly Mid Support 1 ");
SetIndexLabel(2,"Yearly Mid Resistant 1 ");
SetIndexLabel(3,"Yearly Mid Support 2");
SetIndexLabel(4,"Yearly Mid Resistant 2");
SetIndexLabel(5,"Yearly Mid Support 3");
SetIndexLabel(6,"Yearly Mid Resistant 3");
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("Yearly Pivot");
ObjectDelete("Yearly MSup1");
ObjectDelete("Yearly MRes1");
ObjectDelete("Yearly MSup2");
ObjectDelete("Yearly MRes2");
ObjectDelete("Yearly MSup3");
ObjectDelete("Yearly MRes3");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
if(Period()>PERIOD_W1) return(-1);
if(counted_bars==0)
{
ObjectCreate("Yearly Pivot",OBJ_TEXT,0,0,0);
ObjectSetText("Yearly Pivot"," Yearly Pivot Point",8,"Arial",Black);
ObjectCreate("Yearly MSup1",OBJ_TEXT,0,0,0);
ObjectSetText("Yearly MSup1"," yS 1",8,"Arial",White);
ObjectCreate("Yearly MRes1",OBJ_TEXT,0,0,0);
ObjectSetText("Yearly MRes1"," yMR 1",8,"Arial",White);
ObjectCreate("Yearly MSup2",OBJ_TEXT,0,0,0);
ObjectSetText("Yearly MSup2"," yMS 2",8,"Arial",White);
ObjectCreate("Yearly MRes2",OBJ_TEXT,0,0,0);
ObjectSetText("Yearly MRes2"," yMR 2",8,"Arial",White);
ObjectCreate("Yearly MSup3",OBJ_TEXT,0,0,0);
ObjectSetText("Yearly MSup3"," yMS 3",8,"Arial",White);
ObjectCreate("Yearly MRes3",OBJ_TEXT,0,0,0);
ObjectSetText("Yearly MRes3"," yMR 3",8,"Arial",White);
}
for(i=limit-1; i>=0; i--)
{
// 1sts Days of Year
if(TimeDayOfYear(Time[i])<=10 && TimeDayOfYear(Time[i+1])>=355)
{
last_year_close=Close[i+1];
this_year_open=Open[i];
P=(last_year_high+last_year_low+last_year_close+this_year_open)/4;
R1=(((2*P)-last_year_low)-P)/2 +P;
S1=(((2*P)-last_year_high)-P)/2 +P;
R2=((P+(last_year_high-last_year_low))-((2*P)-last_year_low))/2 + (2*P)-last_year_low;
S2=(((2*P)-last_year_high)-(P-(last_year_high-last_year_low)))/2 + P-(last_year_high-last_year_low);
R3=((2*P)+(last_year_high-(2*last_year_low)) - (P+(last_year_high-last_year_low)))/2 + P+(last_year_high-last_year_low);
S3=((P-(last_year_high-last_year_low))-((2*P)-((2*last_year_high)-last_year_low)))/2 + (2*P)-((2*last_year_high)-last_year_low);
ObjectMove("Yearly Pivot",0,Time[i],P);
ObjectMove("Yearly MSup1",0,Time[i],S1);
ObjectMove("Yearly MRes1",0,Time[i],R1);
ObjectMove("Yearly MSup2",0,Time[i],S2);
ObjectMove("Yearly MRes2",0,Time[i],R2);
ObjectMove("Yearly MSup3",0,Time[i],S3);
ObjectMove("Yearly MRes3",0,Time[i],R3);
last_year_low=Low[i];
last_year_high=High[i];
}
last_year_low=MathMin(last_year_low,Low[i]);
last_year_high=MathMax(last_year_high,High[i]);
PBuffer[i]=P;
S1Buffer[i]=S1;
R1Buffer[i]=R1;
S2Buffer[i]=S2;
R2Buffer[i]=R2;
S3Buffer[i]=S3;
R3Buffer[i]=R3;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments