AllPivots_v1_001
Download scriptThis script is designed to automatically calculate and display several types of key price levels—known as "Pivots"—directly on your trading charts. These levels are essential tools for traders who want to identify potential areas of support (where prices might stop falling) and resistance (where prices might stop rising) based on historical data.
The logic follows a structured process to organize these levels visually:
Data Collection
The script looks back at previous trading days to gather three specific pieces of information: the highest price reached (High), the lowest price reached (Low), and the closing price (Close). It uses these figures from the preceding day to project what the "pivot points" might look like for the current period.
Automated Calculations
Once it has gathered the data, the script performs three distinct sets of mathematical calculations:
- Standard Pivot Points: It calculates a central "Pivot Point" (the average of the previous high, low, and close). From there, it derives several "Resistance" levels (R1, R2, R3) and "Support" levels (S1, S2, S3). These represent the primary boundaries for price movement.
- Middle Points: The script calculates a series of intermediate levels (M0 through M5) that bridge the gaps between the standard pivots. These provide a more granular view of the price action.
- Camarilla Levels: This is a specific trading method used to identify "breakout" prices. It calculates eight different levels (H1–H4 and L1–L4) based on the range of the previous day's price action, often used by traders to spot extreme movements or reversals.
Visual Presentation
The script is built to be highly customizable for the user:
- Visibility Toggles: You can choose whether to display the Standard Pivots, the Middle Points, or the Camarilla Levels independently.
- Historical Depth: You can set how many previous days of data you want to see displayed on your chart at once.
- Styling: The script handles all the "heavy lifting" of drawing the lines, assigning them specific colors (like Red for resistance or Green for support), and adjusting their thickness so they are clearly visible but do not clutter your screen.
In summary, this tool transforms raw historical price data into a roadmap of potential supply and demand zones, allowing you to see where the market might face pressure or find stability at a glance.
//+------------------------------------------------------------------+
//| AllPivots_v1.mq4 |
//| Copyright © 2006, 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
extern int CountDays=10;
extern bool Plot_pivots=true;
extern bool Plot_middle=false;
extern bool Plot_camarilla=false;
extern int Pivot_Widths=2;
extern int Midpoint_Widths=1;
extern int Camarilla_Widths=1;
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, pwidth, mwidth, cwidth;
int shift, num;
void ObjDel()
{
for (;num<=CountDays;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, int width)
{
ObjectCreate(name,OBJ_TREND,0,time1,value,time2,value);
ObjectSet(name, OBJPROP_WIDTH, width);
ObjectSet(name, OBJPROP_STYLE, style);
ObjectSet(name, OBJPROP_RAY, false);
ObjectSet(name, OBJPROP_BACK, true);
ObjectSet(name, OBJPROP_COLOR, line_color);
}
int init()
{
return(0);
}
int deinit()
{
ObjDel();
Comment("");
return(0);
}
int start()
{
int i;
ObjDel();
num=0;
for (shift=CountDays-1;shift>=0;shift--)
{
time1=iTime(NULL,PERIOD_D1,shift);
i=shift-1;
if (i<0)
time2=Time[0];
else
time2=iTime(NULL,PERIOD_D1,i)-Period()*60;
high = iHigh(NULL,PERIOD_D1,shift+1);
low = iLow(NULL,PERIOD_D1,shift+1);
open = iOpen(NULL,PERIOD_D1,shift+1);
close = iClose(NULL,PERIOD_D1,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_D1*60;
pstyle=0;
mstyle=3;
cstyle=1;
num=shift;
PlotLine("PP["+num+"]",P,Aqua,pstyle, Pivot_Widths);
if(Plot_pivots)
{
PlotLine("R1["+num+"]",R1,Red,pstyle, Pivot_Widths);
PlotLine("R2["+num+"]",R2,Orange,pstyle, Pivot_Widths);
PlotLine("R3["+num+"]",R3,Gold,pstyle, Pivot_Widths);
PlotLine("S1["+num+"]",S1,MediumSeaGreen,pstyle, Pivot_Widths);
PlotLine("S2["+num+"]",S2,Lime,pstyle, Pivot_Widths);
PlotLine("S3["+num+"]",S3,GreenYellow,pstyle, Pivot_Widths);
}
if(Plot_middle)
{
PlotLine("M0["+num+"]",M0,LightBlue,mstyle, Midpoint_Widths);
PlotLine("M1["+num+"]",M1,DeepSkyBlue,mstyle, Midpoint_Widths);
PlotLine("M2["+num+"]",M2,MediumSlateBlue,mstyle, Midpoint_Widths);
PlotLine("M3["+num+"]",M3,Tomato,mstyle, Midpoint_Widths);
PlotLine("M4["+num+"]",M4,Chocolate,mstyle, Midpoint_Widths);
PlotLine("M5["+num+"]",M5,Pink,mstyle, Midpoint_Widths);
}
if(Plot_camarilla)
{
PlotLine("H4["+num+"]",H4,LightBlue,cstyle, Camarilla_Widths);
PlotLine("H3["+num+"]",H3,DeepSkyBlue,cstyle, Camarilla_Widths);
PlotLine("H2["+num+"]",H2,MediumSlateBlue,cstyle, Camarilla_Widths);
PlotLine("H1["+num+"]",H1,RoyalBlue,cstyle, Camarilla_Widths);
PlotLine("L1["+num+"]",L1,Chocolate,cstyle, Camarilla_Widths);
PlotLine("L2["+num+"]",L2,Orange,cstyle, Camarilla_Widths);
PlotLine("L3["+num+"]",L3,Goldenrod,cstyle, Camarilla_Widths);
PlotLine("L4["+num+"]",L4,Yellow,cstyle, Camarilla_Widths);
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments