WeeklyPivot_001

Download script
Author: Copyright � 2006, Profitrader.
WeeklyPivot_001

This tool is designed to provide traders with a clear visual framework for identifying key price levels on a weekly basis. By automatically calculating and plotting these technical milestones, it helps market participants anticipate potential zones of support and resistance where the price might stall, reverse, or break out.

How the Logic Works

The script operates by analyzing historical price data from the previous trading week to project significant levels for the current week. Here is a breakdown of the logic used:

Data Collection The tool constantly monitors the market's high, low, and closing prices. Specifically, it looks for the transition between weeks to "capture" the extreme boundaries (the highest and lowest points reached) and the final closing price of the preceding week.

Core Calculations Once the previous week's data is captured, the script performs a series of mathematical calculations to establish seven distinct levels:

  • The Weekly Pivot Point: This serves as the central "balance" price for the week. It is calculated by averaging the high, low, and close of the previous week along with the opening price of the current week.
  • Support Levels (S1, S2, S3): These represent "floors." The logic calculates these prices to identify areas where buying interest is expected to increase, potentially preventing the price from falling further.
  • Resistance Levels (R1, R2, R3): These represent "ceilings." The script calculates these to highlight areas where selling pressure is expected to intensify, potentially preventing the price from rising further.

Dynamic Visual Updates The tool is designed to be reactive. As new price action occurs during the week, the script continuously updates its tracking of the current week's high and low. It draws these levels as lines directly on your chart, providing a real-time roadmap of the week's most important structural price points.

Operational Constraints To ensure accuracy and maintain visual clarity, the tool is optimized for specific timeframes. It performs its best when viewed on charts ranging from the Hourly (H1) up to the 4-Hour (H4) periods, ensuring that the weekly levels are scaled appropriately for the trader's perspective.

Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
WeeklyPivot_001
//+------------------------------------------------------------------+
//|                                                     Weekly 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 Magenta
#property indicator_color2 RoyalBlue
#property indicator_color3 Crimson
#property indicator_color4 RoyalBlue
#property indicator_color5 Crimson
#property indicator_color6 SeaGreen
#property indicator_color7 SeaGreen
//---- buffers
double PBuffer[];
double S1Buffer[];
double R1Buffer[];
double S2Buffer[];
double R2Buffer[];
double S3Buffer[];
double R3Buffer[];

double P,S1,R1,S2,R2,S3,R3,last_week_high,last_week_low,last_week_close,this_week_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,0,2);
   SetIndexStyle(2,DRAW_LINE,0,2);
   SetIndexStyle(3,DRAW_LINE,0,2);
   SetIndexStyle(4,DRAW_LINE,0,2);
   SetIndexStyle(5,DRAW_LINE,0,2);
   SetIndexStyle(6,DRAW_LINE,0,2);
   SetIndexLabel(0,"Weekly Pivot Point");
   SetIndexLabel(1,"Weekly Support 1");
   SetIndexLabel(2,"Weekly Resistant 1");
   SetIndexLabel(3,"Weekly Support 2");
   SetIndexLabel(4,"Weekly Resistant 2");
   SetIndexLabel(5,"Weekly Support 3");
   SetIndexLabel(6,"Weekly Resistant 3");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("Weekly Pivot");
   ObjectDelete("Weekly Sup1");
   ObjectDelete("Weekly Res1");
   ObjectDelete("Weekly Sup2");
   ObjectDelete("Weekly Res2");
   ObjectDelete("Weekly Sup3");
   ObjectDelete("Weekly 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_H4) return(-1);
   if(counted_bars==0)
     {
      ObjectCreate("Weekly Pivot",OBJ_TEXT,0,0,0);
      ObjectSetText("Weekly Pivot","                            Weekly Pivot Point",10,"Arial",Red);
      ObjectCreate("Weekly Sup1",OBJ_TEXT,0,0,0);
      ObjectSetText("Weekly Sup1","        wS 1",10,"Arial",Red);
      ObjectCreate("Weekly Res1",OBJ_TEXT,0,0,0);
      ObjectSetText("Weekly Res1","        wR 1",10,"Arial",Red);
      ObjectCreate("Weekly Sup2", OBJ_TEXT,0,0,0);
      ObjectSetText("Weekly Sup2","        wS 2",10,"Arial",Red);
      ObjectCreate("Weekly Res2",OBJ_TEXT,0,0,0);
      ObjectSetText("Weekly Res2","        wR 2",10,"Arial",Red);
      ObjectCreate("Weekly Sup3",OBJ_TEXT,0,0,0);
      ObjectSetText("Weekly Sup3","        wS 3",10,"Arial",Red);
      ObjectCreate("Weekly Res3",OBJ_TEXT,0,0,0);
      ObjectSetText("Weekly Res3","        wR 3",10,"Arial",Red);
     }
   for(i=limit-1; i>=0; i--)
      {
       // 1sts Days of Week
	    if(TimeDayOfWeek(Time[i])<=2 && TimeDayOfWeek(Time[i+1])>=4)
	      {
		    last_week_close=Close[i+1];
		    this_week_open=Open[i];
		    P=(last_week_high+last_week_low+last_week_close+this_week_open)/4;
          R1=(2*P)-last_week_low;
          S1=(2*P)-last_week_high;
          R2=P+(last_week_high-last_week_low);
          S2=P-(last_week_high-last_week_low);
          R3=(2*P)+(last_week_high-(2*last_week_low));
          S3=(2*P)-((2*last_week_high)-last_week_low); 
          ObjectMove("Weekly Pivot",0,Time[i],P);
          ObjectMove("Weekly Sup1",0,Time[i],S1);
          ObjectMove("Weekly Res1",0,Time[i],R1);
          ObjectMove("Weekly Sup2",0,Time[i],S2);
          ObjectMove("Weekly Res2",0,Time[i],R2);
          ObjectMove("Weekly Sup3",0,Time[i],S3);
          ObjectMove("Weekly Res3",0,Time[i],R3);
          last_week_low=Low[i];
          last_week_high=High[i];
         }       
 	    last_week_low=MathMin(last_week_low,Low[i]);   
       last_week_high=MathMax(last_week_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