AllPivots_v2

Download script
Author: Copyright � 2006, Forex-TSD.com
AllPivots_v2

This script is designed as a technical analysis tool for traders who use pivot points to identify potential support and resistance levels in financial markets. It automatically calculates and visualizes several distinct sets of price levels on a trading chart based on historical price data.

Core Functionality

The primary purpose of this script is to take historical data—specifically the high, low, open, and close prices from a specific timeframe—and project calculated "pivot" zones onto your chart. By visualizing these levels, traders can better identify where the market might encounter friction or potential reversal points.

Key Features & Logic

1. Customizable Timeframes The script allows you to choose the historical period used for calculations. You can set it to look at hourly (H1), 4-hour (H4), daily (D1), weekly (W1), or monthly (MN) data. The tool then uses the preceding candle's data to project the levels for the current period.

2. Multi-Layered Pivot Systems The script calculates three different types of price levels, which you can toggle on or off:

  • Standard Pivot Points: These are the classic "P," "R" (Resistance), and "S" (Support) levels. They are calculated using a weighted average of the previous period's high, low, and closing prices.
    • R1, R2, R3: Represent increasing levels of resistance above the current price.
    • S1, S2, S3: Represent increasing levels of support below the current price.
  • Middle Levels (M0-M5): These provide a more granular breakdown between the primary pivot points. They are designed to help traders identify "sub-zones" or intermediate steps within the larger support and resistance boundaries.
  • Camarilla Levels (H1-H4 & L1-L4): This is a specific type of pivot calculation often used by day traders for identifying breakout levels. These lines are calculated based on the "Range" (the difference between high and low) of the previous period, adjusted by specific multipliers to highlight areas of potential volatility.

3. Historical Visualization Rather than just showing you one set of lines for the present moment, the script includes a "CountPeriods" feature. This allows the tool to draw these levels backward in time, providing a visual history of where these key levels were located over previous days or sessions.

4. Visual Organization To ensure the chart remains readable, the script uses different colors and line styles for each category:

  • Pivot Points are displayed as standard solid lines.
  • Middle Levels use a distinct dashed/dotted style to differentiate them from primary levels.
  • Camarilla Levels use a different style again to keep the visual landscape organized.

Summary of Operation

When you apply this script, it scans the historical data for your chosen timeframe, performs the mathematical calculations for all three pivot styles simultaneously, and draws these as horizontal lines across your chart. This gives you a comprehensive "road map" of price levels, allowing you to see where significant market reactions are mathematically likely to occur.

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 open prices of each barSeries array that contains close prices for each bar
7 Views
0 Downloads
0 Favorites
AllPivots_v2
//+------------------------------------------------------------------+
//|                                                 AllPivots_v2.mq4 |
//|                                  Copyright © 2007, Forex-TSD.com |
//|                         Written by IgorAD,igorad2003@yahoo.co.uk |   
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |                                      
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link      "http://www.forex-tsd.com/"

#property indicator_chart_window
#property indicator_buffers   4
#property indicator_color1    LightBlue
#property indicator_color2    Tomato
#property indicator_color3    Aqua
#property indicator_color4    Orange

extern int     CountPeriods=10;
extern string  TimePeriod="D1";
extern bool    Plot_pivots=true;
extern bool    Plot_middle=false;
extern bool    Plot_camarilla=false;

   datetime time1;
   datetime time2;
   double open,close,high,low;
   double P,R1,R2,R3,S1,S2,S3,M0,M1,M2,M3,M4,M5;
   double H1,H2,H3,H4,L1,L2,L3,L4,Range;
   double pstyle, mstyle,cstyle;
   int shift, num, period;
     
   void ObjDel()
   {
      for (;num<=CountPeriods;num++)
      {
      ObjectDelete("PP["+num+"]");
      ObjectDelete("R1["+num+"]");
      ObjectDelete("R2["+num+"]");
      ObjectDelete("R3["+num+"]");
      ObjectDelete("S1["+num+"]");
      ObjectDelete("S2["+num+"]");
      ObjectDelete("S3["+num+"]");
      
      ObjectDelete("M0["+num+"]");
      ObjectDelete("M1["+num+"]");
      ObjectDelete("M2["+num+"]");
      ObjectDelete("M3["+num+"]");
      ObjectDelete("M4["+num+"]");
      ObjectDelete("M5["+num+"]");
      
      ObjectDelete("H1["+num+"]");
      ObjectDelete("H2["+num+"]");
      ObjectDelete("H3["+num+"]");
      ObjectDelete("H4["+num+"]");
      ObjectDelete("L1["+num+"]");
      ObjectDelete("L2["+num+"]");
      ObjectDelete("L3["+num+"]");
      ObjectDelete("L4["+num+"]");
      }
   }

   void PlotLine(string name,double value,double line_color,double style)
   {
   ObjectCreate(name,OBJ_TREND,0,time1,value,time2,value);
   ObjectSet(name, OBJPROP_WIDTH, 1);
   ObjectSet(name, OBJPROP_STYLE, style);
   ObjectSet(name, OBJPROP_RAY, false);
   ObjectSet(name, OBJPROP_BACK, true);
   ObjectSet(name, OBJPROP_COLOR, line_color);
    }        
int init()
  {
   if (TimePeriod=="H1" || TimePeriod=="60") period=PERIOD_H1; 
   else
   if (TimePeriod=="H4" || TimePeriod=="240") period=PERIOD_H4; 
   else
   if (TimePeriod=="D1" || TimePeriod=="1440") period=PERIOD_D1;
   else
   if (TimePeriod=="W1" || TimePeriod=="10080") period=PERIOD_W1; 
   else
   if (TimePeriod=="MN" || TimePeriod=="43200") period=PERIOD_MN1;
   else
   {
   Comment("Wrong TimePeriod. Must be H1, H4, D1, W1 or MN"); 
   return(0);
   }
  return(0);
  }
   
   
int deinit()
  {
   ObjDel();
   Comment("");
   return(0);
  }

int start()
  {
  int i;
     
  ObjDel();
  num=0;
  
  for (shift=CountPeriods-1;shift>=0;shift--)
  {
  time1=iTime(NULL,period,shift);
             
  high  = iHigh(NULL,period,shift+1);
  low   = iLow(NULL,period,shift+1);
  open  = iOpen(NULL,period,shift+1);
  close = iClose(NULL,period,shift+1);
  
  P  = (high+low+close)/3.0;
        
  R1 = 2*P-low;
  R2 = P+(high - low);
  R3 = (2*P)+(high-(2*low));
        
  S1 = 2*P-high;
  S2 = P-(high - low);
  S3 = (2*P)-((2*high)-low);
         
  M0=0.5*(S2+S3);
  M1=0.5*(S1+S2);
  M2=0.5*(P+S1);
  M3=0.5*(P+R1);
  M4=0.5*(R1+R2);
  M5=0.5*(R2+R3);
         
  Range = high - low;
  H4 = close + (Range * 1.1/2.0);
  H3 = close + (Range * 1.1/4.0);
  H2 = close + (Range * 1.1/6.0);
  H1 = close + (Range * 1.1/12.0);

  L1 = close - (Range * 1.1/12.0);
  L2 = close - (Range * 1.1/6.0);
  L3 = close - (Range * 1.1/4.0);
  L4 = close - (Range * 1.1/2.0);
       
  time2=time1+period*60;
         
  pstyle=0;
  mstyle=3;
  cstyle=1;
  num=shift;
       
  PlotLine("PP["+num+"]",P,Aqua,pstyle);
  if(Plot_pivots)
  {
        
   PlotLine("R1["+num+"]",R1,Red,pstyle);
   PlotLine("R2["+num+"]",R2,Orange,pstyle);
   PlotLine("R3["+num+"]",R3,Gold,pstyle);
               
   PlotLine("S1["+num+"]",S1,MediumSeaGreen,pstyle);
   PlotLine("S2["+num+"]",S2,Lime,pstyle);
   PlotLine("S3["+num+"]",S3,GreenYellow,pstyle);
  }
         
  if(Plot_middle)
  {
   PlotLine("M0["+num+"]",M0,LightBlue,mstyle);
   PlotLine("M1["+num+"]",M1,DeepSkyBlue,mstyle);
   PlotLine("M2["+num+"]",M2,MediumSlateBlue,mstyle);
   PlotLine("M3["+num+"]",M3,Tomato,mstyle);
   PlotLine("M4["+num+"]",M4,Chocolate,mstyle);
   PlotLine("M5["+num+"]",M5,Pink,mstyle);
  }
         
  if(Plot_camarilla)
  {
   PlotLine("H4["+num+"]",H4,LightBlue,cstyle);
   PlotLine("H3["+num+"]",H3,DeepSkyBlue,cstyle);
   PlotLine("H2["+num+"]",H2,MediumSlateBlue,cstyle);
   PlotLine("H1["+num+"]",H1,RoyalBlue,cstyle);
      
   PlotLine("L1["+num+"]",L1,Chocolate,cstyle);
   PlotLine("L2["+num+"]",L2,Orange,cstyle);
   PlotLine("L3["+num+"]",L3,Goldenrod,cstyle);
   PlotLine("L4["+num+"]",L4,Yellow,cstyle);
  }
  }
   return(0);
  }
//+------------------------------------------------------------------+

Comments