YearlyPivot

Download script
Author: Copyright � 2006, Profitrader.
YearlyPivot

This script is designed to provide traders with a clear visual representation of key price benchmarks, specifically focusing on yearly levels. It calculates and plots significant "Pivot Points," which serve as potential areas of support and resistance for the current year based on historical data from the previous year.

Core Functionality

The primary purpose of this tool is to identify where price might encounter difficulty moving higher (Resistance) or lower (Support). By automating these calculations, it allows you to see the "geography" of the market for the year at a glance. The script identifies seven specific horizontal levels:

  • Yearly Pivot Point: The central equilibrium level for the year.
  • Resistance Levels (R1, R2, R3): These represent price ceilings where selling pressure typically increases.
  • Support Levels (S1, S2, S3): These represent price floors where buying interest typically strengthens.

How the Logic Works

The script operates using a specific mathematical logic that looks back at the previous year's performance to project the current year's boundaries:

  1. Data Collection: The tool scans historical data to identify the highest price, the lowest price, and the closing price of the preceding year. It also takes into account the opening price of the new year.
  2. Transition Detection: The script is programmed to recognize the "turn of the year." It specifically looks for the transition between late December and early January to reset its calculations and anchor the new levels.
  3. Calculation Methodology:
    • The Pivot (P): This is calculated as the average of four key values: the previous year's high, low, and close, plus the current year's open.
    • Support & Resistance: The subsequent R1 through R3 and S1 through S3 levels are derived from this central Pivot Point. They expand outward to show increasingly stronger zones of potential market reaction. For example, the "S" levels generally project downward from the pivot, while "R" levels project upward.
  4. Dynamic Updating: As the price moves throughout the year, the script constantly monitors the new highs and lows. It ensures that these key benchmarks remain accurate relative to the extremes reached during the current trading period.

Visual Presentation and Usage

  • Timeframe Compatibility: The script is optimized for high-level analysis and is designed to work on weekly charts or higher. It will not display on lower timeframes (like hourly or 15-minute charts) to ensure the yearly perspective remains clear and accurate.
  • On-Chart Labels: To make the chart easy to read, the script automatically places text labels (e.g., "yR 1", "yS 2") next to the lines. This allows you to immediately identify which level is which without having to guess.
  • Visual Cleanup: When the script is removed from your chart, it includes a cleanup routine that deletes all drawn lines and labels, leaving your workspace clean.
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
YearlyPivot
//+------------------------------------------------------------------+
//|                                                     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,4,1);
   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 Support 1");
   SetIndexLabel(2,"Yearly Resistant 1");
   SetIndexLabel(3,"Yearly Support 2");
   SetIndexLabel(4,"Yearly Resistant 2");
   SetIndexLabel(5,"Yearly Support 3");
   SetIndexLabel(6,"Yearly Resistant 3");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("Yearly Pivot");
   ObjectDelete("Yearly Sup1");
   ObjectDelete("Yearly Res1");
   ObjectDelete("Yearly Sup2");
   ObjectDelete("Yearly Res2");
   ObjectDelete("Yearly Sup3");
   ObjectDelete("Yearly Res3");   
   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 Sup1",OBJ_TEXT,0,0,0);
      ObjectSetText("Yearly Sup1","        yS 1",8,"Arial",White);
      ObjectCreate("Yearly Res1",OBJ_TEXT,0,0,0);
      ObjectSetText("Yearly Res1","        yR 1",8,"Arial",White);
      ObjectCreate("Yearly Sup2",OBJ_TEXT,0,0,0);
      ObjectSetText("Yearly Sup2","        yS 2",8,"Arial",White);
      ObjectCreate("Yearly Res2",OBJ_TEXT,0,0,0);
      ObjectSetText("Yearly Res2","        yR 2",8,"Arial",White);
      ObjectCreate("Yearly Sup3",OBJ_TEXT,0,0,0);
      ObjectSetText("Yearly Sup3","        yS 3",8,"Arial",White);
      ObjectCreate("Yearly Res3",OBJ_TEXT,0,0,0);
      ObjectSetText("Yearly Res3","        yR 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;
          S1=(2*P)-last_year_high;
          R2=P+(last_year_high-last_year_low);
          S2=P-(last_year_high-last_year_low);
          R3=(2*P)+(last_year_high-(2*last_year_low));
          S3=(2*P)-((2*last_year_high)-last_year_low); 
        	 ObjectMove("Yearly Pivot",0,Time[i],P);
          ObjectMove("Yearly Sup1",0,Time[i],S1);
          ObjectMove("Yearly Res1",0,Time[i],R1);
          ObjectMove("Yearly Sup2",0,Time[i],S2);
          ObjectMove("Yearly Res2",0,Time[i],R2);
          ObjectMove("Yearly Sup3",0,Time[i],S3);
          ObjectMove("Yearly Res3",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