PivotPointsWeekly_SaM

Download script
Author: Copyright � 2007, BundyRaider
PivotPointsWeekly_SaM

This script is designed for MetaTrader 4 to automatically calculate and display Weekly Pivot Points on a price chart. Pivot points are used by traders to identify potential areas of support (where price might stop falling) and resistance (where price might stop rising).

How the Logic Works

The script automates the heavy lifting of manual calculations by looking back at previous market data to determine key price levels for the current week. Here is a breakdown of the process:

1. Data Collection The script identifies the previous completed week and extracts three specific pieces of information:

  • The highest price reached (High)
  • The lowest price reached (Low)
  • The final price at the end of the week (Close)

2. Automated Calculations Using those three values, the script performs a series of mathematical formulas to generate seven distinct horizontal levels:

  • The Pivot Point (PP): The central equilibrium point of the previous week's price action.
  • Resistance Levels (R1, R2, R3): These are calculated as "ceiling" levels where upward momentum may face pressure.
  • Support Levels (S1, S2, S3): These are calculated as "floor" levels where downward momentum may find a base.

3. Visual Mapping Once the math is complete, the script draws these levels onto your chart automatically:

  • Lines: It creates horizontal lines for all seven levels, using different colors to distinguish between support (typically green) and resistance (typically red/brown).
  • Price Labels: If enabled in the settings, the script places a text label at the end of each line showing the exact price. This allows you to see the specific value of the pivot or support level at a glance without having to hover your mouse over the line.

4. Customization and Performance

  • Time Range: You can choose how many days of historical data you want to see plotted (e.g., only the last 20 days) to keep your chart clean and fast.
  • Visual Styling: The user can adjust the thickness of the lines and the font style/size of the price labels to match their specific trading layout.

Summary for the Trader

Instead of you having to manually calculate these numbers every week, this tool "scans" the previous week's history and instantly plots the key zones where institutional trading activity often occurs. It provides a visual map of where the market might struggle to break through (Resistance) or find a foothold (Support).

Price Data Components
Series array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
2 Views
0 Downloads
0 Favorites
PivotPointsWeekly_SaM
//+------------------------------------------------------------------+
//|                              Auto-Pivot Plotter Weekly V1-00.mq4 |
//|                                  Copyright © 2007, BundyRaider   |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, BundyRaider"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 FireBrick
#property indicator_color2 FireBrick
#property indicator_color3 FireBrick
#property indicator_color4 SlateGray
#property indicator_color5 LimeGreen
#property indicator_color6 LimeGreen
#property indicator_color7 LimeGreen
#property indicator_color8 Green



//---- input parameters
extern int       DaysToPlot = 20; //If DaysToPlot is "0" (zero) we plot ALL available data
extern int       Linewidth = 2;
extern color     cPivot = SlateGray;
extern color     cSupport = LimeGreen;
extern color     cResistance = FireBrick;
extern bool      ShowPriceLabel = true;
extern string    LabelFontType = "Arial Black";
extern int       LabelFontSize = 7;
extern int       LabelShift = 0;


//---- buffers
double Res3[];
double Res2[];
double Res1[];
double Pivot[];
double Supp1[];
double Supp2[];
double Supp3[];
double Extra1[];

datetime LabelShiftTime;
double digits;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,Linewidth,cResistance);
   SetIndexBuffer(0,Res3);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,Linewidth,cResistance);
   SetIndexBuffer(1,Res2);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,Linewidth,cResistance);
   SetIndexBuffer(2,Res1);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,Linewidth,cPivot);
   SetIndexBuffer(3,Pivot);
   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,Linewidth,cSupport);
   SetIndexBuffer(4,Supp1);
   SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,Linewidth,cSupport);
   SetIndexBuffer(5,Supp2);
   SetIndexStyle(6,DRAW_LINE,STYLE_SOLID,Linewidth,cSupport);
   SetIndexBuffer(6,Supp3);
   SetIndexStyle(7,DRAW_LINE,STYLE_SOLID,Linewidth);
   SetIndexBuffer(7,Extra1);
   
   SetIndexLabel(0, "W_R3");
   SetIndexLabel(1, "W_R2");
   SetIndexLabel(2, "W_R1");
   SetIndexLabel(3, "W_PP");
   SetIndexLabel(4, "W_S1");
   SetIndexLabel(5, "W_S2");
   SetIndexLabel(6, "W_S3");
   
   //---- name for DataWindow and indicator subwindow label
   IndicatorShortName("Weekly Pivot Point");

   //----
   SetIndexDrawBegin(0,1);


  digits =  Digits;  
  if(digits == 5 || digits == 3) { digits  = digits - 1 ; } 
   //IndicatorDigits(Digits);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("WRes3");
   ObjectDelete("WRes2");
   ObjectDelete("WRes1");
   ObjectDelete("WeeklyPivot");
   ObjectDelete("WSup1");
   ObjectDelete("WSup2");
   ObjectDelete("WSup3");
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   
   if(counted_bars<0) return(-1);
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   int limit=Bars-counted_bars;
   // ****************************************************
   //    Establish the nuber of bars in a day.
   // ****************************************************
   int BarsInDay=1440/Period();
   
   for(int i=0; i<limit; i++)
   { 

      if ( (i<((DaysToPlot+1)*BarsInDay))||DaysToPlot==0)   // Used to limit the number of days
      {                                                     // that are mapped out. Less waiting ;)
      
      // *****************************************************
      //    Find previous day's opening and closing bars.
      // *****************************************************
      
      //Find Our Week date.

      datetime WeekDate=Time[i];
      int WeeklyBar        =  iBarShift( NULL, PERIOD_W1, WeekDate,false)+1; 
      double PreviousHigh  =  iHigh(NULL, PERIOD_W1,WeeklyBar);
      double PreviousLow   =  iLow(NULL, PERIOD_W1,WeeklyBar);
      double PreviousClose =  iClose(NULL, PERIOD_W1,WeeklyBar);

      
      // ************************************************************************
      //    Calculate Pivot lines and map into indicator buffers.
      // ************************************************************************
      

      double P =  (PreviousHigh+PreviousLow+PreviousClose)/3;
      double R1 = (2*P)-PreviousLow;
      double S1 = (2*P)-PreviousHigh;
      double R2 =  P+(PreviousHigh - PreviousLow);
      double S2 =  P-(PreviousHigh - PreviousLow);
      double R3 = (2*P)+(PreviousHigh-(2*PreviousLow));
      double S3 = (2*P)-((2* PreviousHigh)-PreviousLow); 
      
      LabelShiftTime = Time[LabelShift];
      
   if(ShowPriceLabel)
   {
	
	ObjectCreate("WRes3", OBJ_TEXT, 0, LabelShiftTime, 0);   
   ObjectSetText("WRes3", "               "+DoubleToStr(R3,digits),LabelFontSize,LabelFontType,cResistance);
	SetIndexLabel(0, "WRes3");
	ObjectCreate("WRes2", OBJ_TEXT, 0, LabelShiftTime, 0);
   ObjectSetText("WRes2", "               "+DoubleToStr(R2,digits),LabelFontSize,LabelFontType,cResistance);
   SetIndexLabel(1, "WRes2");
	ObjectCreate("WRes1", OBJ_TEXT, 0, LabelShiftTime, 0);
   ObjectSetText("WRes1", "               "+DoubleToStr(R1,digits),LabelFontSize,LabelFontType,cResistance);
   SetIndexLabel(2, "WRes1");
	ObjectCreate("WeeklyPivot", OBJ_TEXT, 0,LabelShiftTime,0);
   ObjectSetText("WeeklyPivot", "               "+DoubleToStr(P,digits),LabelFontSize,LabelFontType,cPivot);
   SetIndexLabel(3, "WeeklyPivot");
   ObjectCreate("WSup1", OBJ_TEXT, 0, 0, 0);
   ObjectSetText("WSup1", "               "+DoubleToStr(S1,digits),LabelFontSize,LabelFontType,cSupport);
   SetIndexLabel(4, "WSup1");
   ObjectCreate("WSup2", OBJ_TEXT, 0, LabelShiftTime, 0);
   ObjectSetText("WSup2", "               "+DoubleToStr(S2,digits),LabelFontSize,LabelFontType,cSupport);
   SetIndexLabel(5, "WSup2");
   ObjectCreate("WSup3", OBJ_TEXT, 0, LabelShiftTime, 0);   
   ObjectSetText("WSup3", "               "+DoubleToStr(S3,digits),LabelFontSize,LabelFontType,cSupport);
   SetIndexLabel(6, "WSup3");
   
   ObjectMove("WRes3", 0, LabelShiftTime,R3);
   ObjectMove("WRes2", 0, LabelShiftTime,R2);
   ObjectMove("WRes1", 0, LabelShiftTime,R1);
	ObjectMove("WeeklyPivot", 0, LabelShiftTime,P);
   ObjectMove("WSup1", 0, LabelShiftTime,S1);
   ObjectMove("WSup2", 0, LabelShiftTime,S2);
   ObjectMove("WSup3", 0, LabelShiftTime,S3);
   

   } 
    }     
         
     
      Pivot[i]=P; 
      Res1[i] =R1;    
      Res2[i] =R2;  
      Res3[i] =R3;  
      Supp1[i]=S1;   
      Supp2[i]=S2;  
      Supp3[i]=S3;
      // Extra1[i]=OpenPriceAt+i;

      //   **********************************************
      //      Calculate the mid-levels in to the buffers. 
      //      (for mid-levels version)
      //   **********************************************(Twe)
      // Res1[i] =((R1-P)/2)+P;    //M3
      // Res2[i] =((R2-R1)/2)+R1;  //M4
      // Res3[i] =((R3-R2)/2)+R2;  
      // Supp1[i]=((P-S1)/2)+S1;   //M2
      // Supp2[i]=((S1-S2)/2)+S2;  //M1
      // Supp3[i]=((S2-S3)/2)+S3;


       //End of 'DaysToPlot 'if' statement.
   }   
      // ***************************************************************************************
      //                            End of Main Loop
      // ***************************************************************************************


   // *****************************************
   //    Return from Start() (Main Routine)
   return(0);
  }
//+-------------------------------------------------------------------------------------------------------+
//  END Custom indicator iteration function
//+-------------------------------------------------------------------------------------------------------+


// *****************************************************************************************
// *****************************************************************************************
// -----------------------------------------------------------------------------------------
//    The following routine will use "StartingBar"'s time and use it to find the 
//    general area that SHOULD contain the bar that matches "TimeToLookFor"
// -----------------------------------------------------------------------------------------


Comments