The XIT_FIBS tool is an automated technical analysis indicator designed to identify and visualize key Fibonacci retracement levels on your trading chart. Rather than requiring the user to manually click and drag tools to find significant price points, this script dynamically scans the visible portion of your current chart to perform these calculations automatically.
Core Logic and Functionality
1. Automatic High and Low Detection The primary logic of the script revolves around "scanning" the visible screen area of your chart. It automatically searches for the highest peak (highest price) and the lowest valley (lowest price) within the current window you are viewing. By doing this, the tool ensures that the Fibonacci levels are always relevant to the specific price action you are currently analyzing.
2. Dynamic Trend Orientation The script is designed to be intelligent regarding market direction. It compares the chronological order of the highest and lowest points found:
- Bearish Trends: If the highest point occurred before the lowest point, it identifies a downward move and applies specific visual formatting (Red).
- Bullish Trends: If the lowest point occurred before the highest point, it identifies an upward move and adjusts the orientation accordingly (Green).
3. Precise Level Calculation Once the extremes are identified, the script calculates the mathematical distance between the high and low points. It then projects six standard Fibonacci retracement levels based on this distance:
- 0.0% (The start of the move)
- 23.6%
- 38.2%
- 50.0% (The midpoint)
- 61.8% (The "Golden Ratio")
- 100.0% (The end of the move)
4. Visual Presentation and Labeling To make the data easy to read at a glance, the script does more than just draw lines; it provides clear context:
- Dynamic Labeling: It converts the raw mathematical calculations into formatted text labels on your chart, showing you the exact price value for each percentage level.
- Styling: The tool automatically applies a specific dashed-dot line style and consistent width to ensure that the Fibonacci levels are clearly visible without cluttering your workspace.
- Clean Environment: The script includes initialization and deinitialization protocols that ensure the chart remains clean by removing the old indicator elements when it is removed or refreshed, preventing "ghost" lines from appearing on your screen.
//+------------------------------------------------------------------+
//| XIT_FIBS.mq4 |
//| Copyright © 2011, Jeff West - Forex-XIT |
//| http://www.forex-xit.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Jeff West - Forex-XIT"
#property link "http://www.forex-xit.com"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
ObjectDelete("XIT_FIBO");
Comment("");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("XIT_FIBO");
Comment("");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
int fibHigh = iHighest(Symbol(),Period(),MODE_HIGH,WindowFirstVisibleBar()-1,1);
int fibLow = iLowest(Symbol(),Period(),MODE_LOW,WindowFirstVisibleBar()-1,1);
datetime highTime = Time[fibHigh];
datetime lowTime = Time[fibLow];
if(fibHigh>fibLow){
WindowRedraw();
ObjectCreate("XIT_FIBO",OBJ_FIBO,0,highTime,High[fibHigh],lowTime,Low[fibLow]);
color levelColor = Red;
}
else{
WindowRedraw();
ObjectCreate("XIT_FIBO",OBJ_FIBO,0,lowTime,Low[fibLow],highTime,High[fibHigh]);
levelColor = Green;
}
double fiboPrice1=ObjectGet("XIT_FIBO",OBJPROP_PRICE1);
double fiboPrice2=ObjectGet("XIT_FIBO",OBJPROP_PRICE2);
double fiboPriceDiff = fiboPrice2-fiboPrice1;
string fiboValue0 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.0,Digits);
string fiboValue23 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.236,Digits);
string fiboValue38 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.382,Digits);
string fiboValue50 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.50,Digits);
string fiboValue61 = DoubleToStr(fiboPrice2-fiboPriceDiff*0.618,Digits);
string fiboValue100 = DoubleToStr(fiboPrice2-fiboPriceDiff*1.0,Digits);
ObjectSet("XIT_FIBO",OBJPROP_FIBOLEVELS,6);
ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+0,0.0);
ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+1,0.236);
ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+2,0.382);
ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+3,0.50);
ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+4,0.618);
ObjectSet("XIT_FIBO",OBJPROP_FIRSTLEVEL+5,1.0);
ObjectSet("XIT_FIBO",OBJPROP_LEVELCOLOR,levelColor);
ObjectSet("XIT_FIBO",OBJPROP_LEVELWIDTH,1);
ObjectSet("XIT_FIBO",OBJPROP_LEVELSTYLE,STYLE_DASHDOTDOT);
ObjectSetFiboDescription( "XIT_FIBO", 0,fiboValue0+" --> 0.0%");
ObjectSetFiboDescription( "XIT_FIBO", 1,fiboValue23+" --> 23.6%");
ObjectSetFiboDescription( "XIT_FIBO", 2,fiboValue38+" --> 38.2%");
ObjectSetFiboDescription( "XIT_FIBO", 3,fiboValue50+" --> 50.0%");
ObjectSetFiboDescription( "XIT_FIBO", 4,fiboValue61+" --> 61.8%");
ObjectSetFiboDescription( "XIT_FIBO", 5,fiboValue100+" --> 100.0%");
//----
return(0);
}
//+------------------------------------------------------------------+
Comments