Fib SR
Download scriptThis tool is designed to automatically identify and plot key price levels on your trading chart based on daily market data. By analyzing the previous day's price action, it calculates specific support and resistance zones to help traders visualize potential areas where the market might encounter difficulty moving higher or lower.
How the Logic Works
The script operates by looking specifically at the "Daily" timeframe. Every time a new trading day begins, the tool performs a calculation based on three primary pieces of information from the previous completed day:
- The High: The highest price reached during the day.
- The Low: The lowest price reached during the day.
- The Close: The final price at which the market finished for the day.
The Calculation Process
Once it gathers those three points, the script follows a structured mathematical sequence to determine your trading zones:
- Range Identification: It first calculates the total price range (the distance between the high and the low).
- Pivot Point Discovery: It finds a central "mean" or balance point by averaging the high, low, and closing prices.
- Support and Resistance Zones: Using that center point and the daily range, it projects out specific levels:
- Resistance Levels: These represent overhead areas where selling pressure might increase. The script calculates these as price targets above the current balance point.
- Support Levels: These represent "floor" areas where buying interest may strengthen. The script calculates these as price targets below the current balance point.
- Fibonacci Extensions: To provide a more comprehensive view of market volatility, the tool also projects deeper extensions using standard Fibonacci ratios (specifically 0.618 and 1.382). This helps identify "extreme" zones where prices might see significant reactions.
Visual Presentation
Instead of just showing single lines, the script draws rectangles on your chart. These visual blocks represent price zones rather than exact points. This is a professional approach to charting because it acknowledges that markets often react within a range of prices rather than hitting one specific cent perfectly.
The zones are color-coded automatically:
- Support Zones: Displayed in cooler tones (Blue/Aqua) to signify "safety" or buying floors.
- Resistance Zones: Displayed in warmer tones (Coral/Tan) to signify "ceiling" areas or selling pressure.
Automation Features
The script is designed for a seamless user experience:
- Automatic Refresh: It detects the start of a new day and automatically clears out the old data, recalculating and redrawing the boxes for the new session without any manual intervention.
- Real-Time Accuracy: Because it relies on the "Daily" close, the levels remain stable throughout the current trading day, providing you with a consistent roadmap for your price action analysis.
//+------------------------------------------------------------------+
//| Fib SR.mq4 |
//| Copyright © 2006, Eli hayun |
//| http://www.elihayun.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Eli hayun"
#property link "http://www.elihayun.com"
#property indicator_chart_window
#define FIB_SUP1 "FIB_SUP_1"
#define FIB_SUP2 "FIB_SUP_2"
#define FIB_RES1 "FIB_RES_1"
#define FIB_RES2 "FIB_RES_2"
extern color clrSup1 = DeepSkyBlue;
extern color clrSup2 = Aqua;
extern color clrRes1 = Coral;
extern color clrRes2 = Tan;
double A, B, C, D, E;
double A1, B1, D1, E1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
Recalc();
ObjectDelete(FIB_SUP1);
ObjectDelete(FIB_SUP2);
ObjectDelete(FIB_RES1);
ObjectDelete(FIB_RES2);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
static datetime dt = 0;
if (dt != iTime(NULL, PERIOD_D1,0))
{
Recalc();
dt = iTime(NULL, PERIOD_D1,0);
}
if (NewBar())
{
ObjectDelete(FIB_SUP1);
ObjectDelete(FIB_SUP2);
ObjectDelete(FIB_RES1);
ObjectDelete(FIB_RES2);
ObjectCreate(FIB_SUP1, OBJ_RECTANGLE, 0, iTime(NULL, PERIOD_D1, 0), B, Time[0], B1); ObjectSet(FIB_SUP1, OBJPROP_COLOR, clrSup1);
ObjectCreate(FIB_SUP2, OBJ_RECTANGLE, 0, iTime(NULL, PERIOD_D1, 0), A, Time[0], A1); ObjectSet(FIB_SUP2, OBJPROP_COLOR, clrSup2);
ObjectCreate(FIB_RES1, OBJ_RECTANGLE, 0, iTime(NULL, PERIOD_D1, 0), D, Time[0], D1); ObjectSet(FIB_RES1, OBJPROP_COLOR, clrRes1);
ObjectCreate(FIB_RES2, OBJ_RECTANGLE, 0, iTime(NULL, PERIOD_D1, 0), E, Time[0], E1); ObjectSet(FIB_RES2, OBJPROP_COLOR, clrRes2);
}
return(0);
}
//+------------------------------------------------------------------+
bool NewBar()
{
static datetime dt = 0;
if (dt != Time[0])
{
dt = Time[0];
return(true);
}
return(false);
}
void Recalc()
{
double C = iClose(NULL, PERIOD_D1, 1); // Yesterday close
double L = iLow(NULL, PERIOD_D1, 1); // Yesterday Low
double H = iHigh(NULL, PERIOD_D1, 1); // Yesterday High
double R = (H-L);
C = (H+L+C) / 3;
D = (R/2) + C;
B = C - (R/2);
E = R + C;
A = C - R;
B1 = C - ( R * 0.618 );
A1 = C - ( R * 1.382 );
D1 = C + ( R * 0.618 );
E1 = C + ( R * 1.382 );
}
Comments