AllPivots_v1
Download scriptThis script is designed as a visual trading tool for the MetaTrader platform. Its primary purpose is to automatically calculate and display various "Pivot Points"—which are specific price levels used by traders to identify potential areas of support (where prices might stop falling) and resistance (where prices might stop rising).
Core Functionality
The script analyzes historical daily price data to project these key levels onto your current chart. Instead of requiring you to calculate these complex mathematical figures manually, the tool draws them as clear horizontal lines across your screen.
How the Logic Works
The script processes information based on a specific timeframe (Daily) and looks back at a user-defined number of previous days (defaulting to 30). For each of those historical days, it extracts three main pieces of data: the High, the Low, and the Closing price.
Using these three figures, the script performs several sets of calculations to generate different types of market levels:
- Standard Pivot Points: It calculates a central "Pivot" price based on the average of the previous day's range. From there, it generates three Resistance lines (R1, R2, R3) and three Support lines (S1, S2, S3).
- Middle Levels: The script can calculate a series of intermediate levels (M0 through M5) which provide more granular data points between the major pivots.
- Camarilla Levels: It includes logic to plot "Camarilla" levels (H1–H4 and L1–L4). These are specialized levels often used by day traders to identify break-out points and range boundaries.
Visual Organization
To keep the chart clean and readable, the script handles the visual elements automatically:
- Automatic Drawing: It creates the lines on your chart in real-time, assigning specific colors (such as Red, Lime, Yellow, and Blue) to different levels so you can distinguish between support and resistance at a glance.
- Dynamic Cleanup: Every time the chart updates or is refreshed, the script clears the old lines and redraws them correctly. This ensures that your chart doesn't become cluttered with "ghost" lines from past calculations.
- Customizable Visibility: You can choose to toggle different sets of levels (like the Middle levels or the Camarilla levels) on or off depending on your personal trading style.
In summary, this tool automates the heavy lifting of technical analysis by taking historical daily price movement and turning it into a visual roadmap of potential price targets for your current trading session.
//+------------------------------------------------------------------+
//| 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=30;
extern bool Plot_pivots=true;
extern bool Plot_middle=false;
extern bool Plot_camarilla=true;
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;
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)
{
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()
{
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=0;
num=shift;
PlotLine("PP["+num+"]",P,Aqua,pstyle);
if(Plot_pivots)
{
PlotLine("R1["+num+"]",R1,Yellow,cstyle);
PlotLine("R2["+num+"]",R2,Lime,cstyle);
PlotLine("R3["+num+"]",R3,Red,cstyle);
PlotLine("S1["+num+"]",S1,Yellow,cstyle);
PlotLine("S2["+num+"]",S2,Lime,cstyle);
PlotLine("S3["+num+"]",S3,Red,cstyle);
}
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