AllPivots_v2_001
Download scriptThis script is designed to automate the visual mapping of key price levels on your trading chart, specifically focusing on "Pivot Points" and Fibonacci-based retracement levels. It serves as a historical reference tool that allows traders to see where significant price boundaries were established over a specific number of previous days.
Core Functionality
The logic operates by scanning through the past days of market data (based on the number of days you specify in the settings). For each day, the script identifies three critical price points: the highest point reached (High), the lowest point reached (Low), and the final price at the end of that period (Close).
Key Components Explained
1. Standard Pivot Points The script calculates several standard support and resistance levels for each historical day. These include:
- The Pivot Point (P): The central "balance" point calculated by averaging the previous day's high, low, and close.
- Resistance Levels (R1, R2, R3): These represent potential "ceilings" or areas where price might face selling pressure.
- Support Levels (S1, S2, S3): These represent potential "floors" or areas where price might find buying interest.
2. Fibonacci Pivot Levels In addition to standard pivots, the script calculates advanced levels based on Fibonacci ratios. These are used by many traders to identify specific percentages of retracement within a trading range. It identifies six distinct lines (three for resistance and three for support) to help pinpoint more nuanced reversal zones.
3. OHLC Reference Points The script also has the capability to plot "Open, High, Low, Close" markers. This allows you to see exactly where the market opened and at its extreme points during previous sessions, providing a clear visual history of daily price movement.
Visual Management
To keep your chart clean and professional:
- Automatic Organization: The script automatically organizes these lines into groups based on the day they occurred.
- Customization: You can choose to toggle specific sets of data on or off (for example, you can view only the standard pivots while hiding the Fibonacci levels, or vice versa).
- Dynamic Refreshing: Every time the chart updates, the script clears out old drawings and redraws them instantly. This ensures that the information displayed is always accurate and synced with the current time and price action.
In summary, this tool acts as a historical "map," projecting previous days' boundaries onto your current chart so you can identify recurring patterns and significant price zones more efficiently.
//+------------------------------------------------------------------+
//| 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_ohlc=true;
extern bool Plot_fibpivots=true;
datetime time1;
datetime time2;
double open,close,high,low;
double P,R1,R2,R3,S1,S2,S3,M0,M1,M2;
int shift, num;
void ObjDel()
{
for (;num<=CountDays;num++)
{
ObjectDelete("Pivot["+num+"]");
ObjectDelete("R1["+num+"]");
ObjectDelete("R2["+num+"]");
ObjectDelete("R3["+num+"]");
ObjectDelete("S1["+num+"]");
ObjectDelete("S2["+num+"]");
ObjectDelete("S3["+num+"]");
ObjectDelete("Y_High["+num+"]");
ObjectDelete("T_Open["+num+"]");
ObjectDelete("Y_low["+num+"]");
ObjectDelete("FibR3["+num+"]");
ObjectDelete("FibR2["+num+"]");
ObjectDelete("FibR1["+num+"]");
ObjectDelete("FibS1["+num+"]");
ObjectDelete("FibS2["+num+"]");
ObjectDelete("FibS3["+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=high;
M1=iOpen(NULL,PERIOD_D1,shift);
M2=low;
double q,p,fibr3,fibr2,fibr1,fibs1,fibs2,fibs3;
q = (high - low);
p = (high + low + close) / 3;
fibr3 = p + (q * 1.000);
fibr2 = p + (q * 0.618);
fibr1 = p + (q * 0.382);
fibs1 = p - (q * 0.382);
fibs2 = p - (q * 0.618);
fibs3 = p - (q * 1.000);
time2=time1+PERIOD_D1*60;
num=shift;
PlotLine("Pivot["+num+"]",P,RoyalBlue,0, 1);
if(Plot_pivots)
{
PlotLine("R1["+num+"]",R1,Maroon,0, 1);
PlotLine("R2["+num+"]",R2,Crimson,0, 1);
PlotLine("R3["+num+"]",R3,Red,0, 1);
PlotLine("S1["+num+"]",S1,DarkGreen,0, 1);
PlotLine("S2["+num+"]",S2,Green,0, 1);
PlotLine("S3["+num+"]",S3,Lime,0, 1);
}
if(Plot_ohlc)
{
PlotLine("Y_High["+num+"]",M0,White,3, 1);
PlotLine("T_Open["+num+"]",M1,Yellow,3, 1);
PlotLine("Y_Low["+num+"]",M2,White,3, 1);
}
if(Plot_fibpivots)
{
PlotLine("FibR3["+num+"]",fibr3,Red,2, 1);
PlotLine("FibR2["+num+"]",fibr2,Crimson,2, 1);
PlotLine("FibR1["+num+"]",fibr1,Maroon,2, 1);
PlotLine("FibS1["+num+"]",fibs1,DarkGreen,2, 1);
PlotLine("FibS2["+num+"]",fibs2,Green,2, 1);
PlotLine("FibS3["+num+"]",fibs3,Lime,2, 1);
}
}
return(0);
}
//+------------------------------------------------------------------+
Comments