Pivot Support Resistance Auto
Download scriptThis tool is designed to automate the identification of key price levels on your trading chart by combining two popular technical analysis methods: Pivot Points and Fibonacci Retracements. It provides a visual roadmap of where significant support and resistance levels might occur based on previous market activity.
How it Works
1. Data Collection The script automatically looks back at the previous day's trading data to identify three critical price points:
- The highest price reached (High)
- The lowest price reached (Low)
- The final closing price (Close)
It is specifically designed to handle weekends intelligently; if the market is open on a Monday, it correctly identifies the last full trading day (Friday) to ensure the calculations remain accurate.
2. Core Calculations Once the high, low, and close prices are gathered, the script performs two types of math:
- Standard Pivot Calculation: It finds the "median" price of the previous day by averaging the High, Low, and Close. This serves as the central balance point for the current session.
- Range Assessment: It calculates the total distance between yesterday’s high and low.
3. Level Generation The script then uses that range to project six specific levels on your chart:
- Resistance Levels (R1, R2, R3): These are calculated above the central Pivot point. They represent potential "ceilings" where price might struggle to climb higher.
- Support Levels (S1, S2, S3): These are calculated below the central Pivot point. They represent potential "floors" where price might find a base to bounce back up from.
The specific percentages used for these levels (such as 0.382, 0.618, and 1.000) are derived from Fibonacci sequences, which many traders believe highlight natural areas of psychological interest in the market.
Visual Presentation
To make the data easy to read at a glance, the script automatically draws:
- Horizontal Lines: Clearly demarcated lines showing exactly where each level sits on the price scale.
- Text Labels: Descriptive labels (e.g., "Resistance 1", "Support 2") are placed next to the lines so you can identify them instantly.
- Color Coding: The script uses a color-coded system—typically using shades of green/lime for Resistance levels, red/maroon for Support levels, and blue for the main Pivot point—allowing for quick visual orientation.
Summary for Traders
Essentially, this script removes the manual work of calculating complex formulas. It allows you to see at a glance where the market's "danger zones" and "rebound zones" are located based on yesterday’s performance, helping you better plan your entry and exit points.
//+------------------------------------------------------------------+
//| FiboPiv_v1.mq4 |
//| Kalenzo |
//| bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link "bartlomiej.gorski@gmail.com"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("S1");
ObjectDelete("S2");
ObjectDelete("S3");
ObjectDelete("R1");
ObjectDelete("R2");
ObjectDelete("R3");
ObjectDelete("PIVOT");
ObjectDelete("Support 1");
ObjectDelete("Support 2");
ObjectDelete("Support 3");
ObjectDelete("Piviot level");
ObjectDelete("Resistance 1");
ObjectDelete("Resistance 2");
ObjectDelete("Resistance 3");
Comment(" ");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
double rates[1][6],yesterday_close,yesterday_high,yesterday_low;
ArrayCopyRates(rates, Symbol(), PERIOD_D1);
if(DayOfWeek() == 1)
{
if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,1)) == 5)
{
yesterday_close = rates[1][4];
yesterday_high = rates[1][3];
yesterday_low = rates[1][2];
}
else
{
for(int d = 5;d>=0;d--)
{
if(TimeDayOfWeek(iTime(Symbol(),PERIOD_D1,d)) == 5)
{
yesterday_close = rates[d][4];
yesterday_high = rates[d][3];
yesterday_low = rates[d][2];
}
}
}
}
else
{
yesterday_close = rates[1][4];
yesterday_high = rates[1][3];
yesterday_low = rates[1][2];
}
//---- Calculate Pivots
Comment("\nYesterday quotations:\nH ",yesterday_high,"\nL ",yesterday_low, "\nC ",yesterday_close);
double R = yesterday_high - yesterday_low;//range
double p = (yesterday_high + yesterday_low + yesterday_close)/3;// Standard Pivot
double r3 = p + (R * 1.000);
double r2 = p + (R * 0.618);
double r1 = p + (R * 0.382);
double s1 = p - (R * 0.382);
double s2 = p - (R * 0.618);
double s3 = p - (R * 1.000);
drawLine(r3,"R3", Lime,0);
drawLabel("Resistance 3",r3,Lime);
drawLine(r2,"R2", Green,0);
drawLabel("Resistance 2",r2,Green);
drawLine(r1,"R1", DarkGreen,0);
drawLabel("Resistance 1",r1,DarkGreen);
drawLine(p,"PIVOT",Blue,1);
drawLabel("Piviot level",p,Blue);
drawLine(s1,"S1",Maroon,0);
drawLabel("Support 1",s1,Maroon);
drawLine(s2,"S2",Crimson,0);
drawLabel("Support 2",s2,Crimson);
drawLine(s3,"S3",Red,0);
drawLabel("Support 3",s3,Red);
//----
return(0);
}
//+------------------------------------------------------------------+
void drawLabel(string name,double lvl,color Color)
{
if(ObjectFind(name) != 0)
{
ObjectCreate(name, OBJ_TEXT, 0, Time[10], lvl);
ObjectSetText(name, name, 8, "Arial", EMPTY);
ObjectSet(name, OBJPROP_COLOR, Color);
}
else
{
ObjectMove(name, 0, Time[10], lvl);
}
}
void drawLine(double lvl,string name, color Col,int type)
{
if(ObjectFind(name) != 0)
{
ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
if(type == 1)
ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
else
ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
ObjectSet(name, OBJPROP_COLOR, Col);
ObjectSet(name,OBJPROP_WIDTH,1);
}
else
{
ObjectDelete(name);
ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);
if(type == 1)
ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);
else
ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);
ObjectSet(name, OBJPROP_COLOR, Col);
ObjectSet(name,OBJPROP_WIDTH,1);
}
}
Comments