Author: Copyright � 2006, Eli hayun

Technical Overview: FibSR Indicator

The FibSR is a specialized technical analysis tool designed for the MetaTrader 5 platform. It automates the visual identification of key price zones—specifically Support and Resistance levels—based on a calculated mathematical relationship between a period's high, low, and closing prices.

Unlike standard indicators that might only plot lines, this script dynamically renders visual "zones" (colored rectangles) on your chart to highlight areas where price action may encounter significant friction or reversal.


Core Operational Logic

The indicator operates by analyzing specific price data from a user-defined timeframe (defaulting to the H6 timeframe). The logic follows a structured three-step process:

1. Data Acquisition

The script continuously monitors the most recent completed candle. It captures three primary metrics:

  • High Price: The highest point reached in that period.
  • Low Price: The lowest point reached in that period.
  • Close Price: The price at which the period finished.

2. Mathematical Calculation

Once these three values are captured, the script performs a series of calculations to determine the "center" of the price action and the relative volatility:

  • Range & Average: It determines the total price range (High minus Low) and calculates a weighted average price point.
  • Volatility Projections: Using these base figures, it derives four distinct zones. These zones are calculated using specific multipliers (such as 0.618 and 1.382), which are inspired by Fibonacci-style proportions used in market analysis to predict where trends might exhaust themselves.

3. Visual Rendering

The final output is the automated drawing of four colored rectangles on your trading chart:

  • Resistance Zones (Upper): Two zones (colored Green and Lime) are projected above the current price action. These represent potential "ceilings" where selling pressure may increase.
  • Support Zones (Lower): Two zones (colored Red and Magenta) are projected below the current price action. These represent potential "floors" where buying interest may emerge.

Key User Features

  • Dynamic Updates: The rectangles automatically shift and resize in real-time as new candles form, ensuring the support and resistance levels remain current with the latest market data.
  • Multi-Timeframe Compatibility: Users can set a specific timeframe for the calculations, allowing them to view higher-level structural zones while trading on lower-level charts.
  • Visual Clarity: By using filled rectangles rather than thin lines, the indicator provides a "zone of interest," acknowledging that support and resistance are often areas of price activity rather than exact single points.
8 Views
0 Downloads
0 Favorites
fib_sr
//+------------------------------------------------------------------+
//|                                                        FibSR.mq5 |
//|                                      Copyright © 2006, Eli hayun |
//|                                          http://www.elihayun.com |
//+------------------------------------------------------------------+
//--- Copyright
#property copyright "Copyright © 2006, Eli hayun"
//--- link to the website of the author
#property link      "http://www.elihayun.com"
//--- Indicator version
#property version   "1.00"
//--- drawing the indicator in the main window
#property indicator_chart_window 
//--- buffers are not used for indicator calculation and drawing
#property indicator_buffers 0
//--- no graphical constructions
#property indicator_plots   0
//+------------------------------------------------+ 
//|  Declaration of constants                      |
//+------------------------------------------------+
#define RESET     0            // A constant for returning the indicator recalculation command to the terminal
#define FIB_RES2 "FIB_RES_2"
#define FIB_RES1 "FIB_RES_1"
#define FIB_SUP1 "FIB_SUP_1"
#define FIB_SUP2 "FIB_SUP_2"
//+----------------------------------------------+
//| Indicator input parameters                   |
//+----------------------------------------------+
input ENUM_TIMEFRAMES Timeframe=PERIOD_H6;  // Indicator timeframe for the indicator calculation
input color  Color_Res2 = clrLime;          // The color of the second resistance zone
input color  Color_Res1 = clrGreen;         // The color of the first resistance zone
input color  Color_Sup1 = clrRed;           // The color of the first support zone
input color  Color_Sup2 = clrMagenta;       // The color of the second support zone
//+------------------------------------------------------------------+
//|  Creating a rectangle object                                     |
//+------------------------------------------------------------------+
void CreateRectangle(long     chart_id,      // Chart ID
                     string   name,          // object name
                     int      nwin,          // window index
                     datetime time1,         // time 1
                     double   price1,        // price 1
                     datetime time2,         // time 2
                     double   price2,        // price 2
                     color    Color,         // line color
                     bool     background,    // line background display
                     string   text)          // text
  {
   ObjectCreate(chart_id,name,OBJ_RECTANGLE,nwin,time1,price1,time2,price2);
   ObjectSetInteger(chart_id,name,OBJPROP_COLOR,Color);
   ObjectSetInteger(chart_id,name,OBJPROP_FILL,true);
   ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
   ObjectSetInteger(chart_id,name,OBJPROP_BACK,background);
   ObjectSetString(chart_id,name,OBJPROP_TOOLTIP,"\n"); // tooltip disabling
   ObjectSetInteger(chart_id,name,OBJPROP_BACK,true); // background object
  }
//+------------------------------------------------------------------+
//|  Resetting the rectangle object                                  |
//+------------------------------------------------------------------+
void SetRectangle(long     chart_id,      // Chart ID
                  string   name,          // object name
                  int      nwin,          // window index
                  datetime time1,         // time 1
                  double   price1,        // price 1
                  datetime time2,         // time 2
                  double   price2,        // price 2
                  color    Color,         // line color
                  bool     background,    // line background display
                  string   text)          // text
  {
   if(ObjectFind(chart_id,name)==-1) CreateRectangle(chart_id,name,nwin,time1,price1,time2,price2,Color,background,text);
   else
     {
      ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
      ObjectMove(chart_id,name,0,time1,price1);
      ObjectMove(chart_id,name,1,time2,price2);
     }
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+  
int OnInit()
  {
//---
   if(Period()>=Timeframe) return(INIT_FAILED);;
//--- Determining the accuracy of displaying the indicator values
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits);
//--- Creating labels for displaying in DataWindow and the name for displaying in a separate sub-window and in a tooltip
   IndicatorSetString(INDICATOR_SHORTNAME,"FibSR");
//--- initialization end
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+    
void OnDeinit(const int reason)
  {
   ObjectDelete(0,FIB_SUP1);
   ObjectDelete(0,FIB_SUP2);
   ObjectDelete(0,FIB_RES1);
   ObjectDelete(0,FIB_RES2);
//---
   ChartRedraw(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,    // number of bars in history at the current tick
                const int prev_calculated,// amount of history in bars at the previous tick
                const datetime &time[],
                const double &open[],
                const double& high[],     // price array of price maximums for the indicator calculation
                const double& low[],      // price array of minimums of price for the indicator calculation
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   if(prev_calculated==rates_total) return(rates_total);

   double iClose[1],iHigh[1],iLow[1];
   datetime iTime[1];
   int to_copy;

//--- indexing elements in arrays as in timeseries  
   ArraySetAsSeries(time,true);

   to_copy=1;

   if(CopyTime(NULL,Timeframe,0,to_copy,iTime)<to_copy)return(RESET);
   if(CopyClose(NULL,Timeframe,1,to_copy,iClose)<to_copy)return(RESET);
   if(CopyHigh(NULL,Timeframe,1,to_copy,iHigh)<to_copy)return(RESET);
   if(CopyLow(NULL,Timeframe,1,to_copy,iLow)<to_copy)return(RESET);

   double C=iClose[0];
   double H=iHigh[0];
   double L=iLow[0];
   double R=(H-L);
//---
   C=(H+L+C)/3;
   double D=(R/2)+C;
   double B=C-(R/2);
   double E=R+C;
   double A=C-R;
//---
   double R1=R*1.382;
   double R2=R*0.618;
   double B1=C-R2;
   double A1=C-R1;
//---
   double D1=C+R2;
   double E1=C+R1;
//---
   SetRectangle(0,FIB_RES2,0,iTime[0],E,time[0],E1,Color_Res2,true,FIB_RES2);
   SetRectangle(0,FIB_RES1,0,iTime[0],D,time[0],D1,Color_Res1,true,FIB_RES1);
   SetRectangle(0,FIB_SUP1,0,iTime[0],B,time[0],B1,Color_Sup1,true,FIB_SUP1);
   SetRectangle(0,FIB_SUP2,0,iTime[0],A,time[0],A1,Color_Sup2,true,FIB_SUP2);
//---
   ChartRedraw(0);
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments