XIT_FIBS_mod_1

Download script
Author: Copyright 2017, MetaQuotes Software Corp.
XIT_FIBS_mod_1

This script is designed to automate the drawing of Fibonacci retracement levels on a trading chart. For traders who use Fibonacci tools to identify potential support and resistance zones, this tool removes the manual work of identifying price extremes and placing the lines yourself.

Core Logic Overview

The script functions by constantly monitoring the visible area of your current trading chart to identify key price points. Here is the step-by-step logic it follows:

1. Automatic Price Detection Instead of waiting for a user to click on a high or low point, the script automatically scans the currently visible bars on your screen. It identifies two critical coordinates:

  • The absolute highest price reached within the visible window.
  • The absolute lowest price reached within the visible window.

2. Dynamic Orientation The script is intelligent enough to recognize the direction of the market trend based on those two points.

  • If the highest point occurred before the lowest point (an uptrend move), it maps the Fibonacci levels accordingly.
  • If the lowest point occurred before the highest point (a downtrend move), it flips the orientation to ensure the retracement levels align correctly with the price action.

3. Visual Customization The script allows for specific visual preferences without affecting the underlying logic:

  • Color: You can set a custom color for the Fibonacci lines.
  • Style: You can choose the line style (e.g., solid, dashed, or dotted).
  • Width: You can adjust how thick the lines appear on your screen.

4. Standard Level Mapping Once the high and low points are identified and the orientation is set, the script automatically draws six standard Fibonacci levels:

  • 0.0%
  • 23.6%
  • 38.2%
  • 50.0%
  • 61.8%
  • 100.0%

User Experience

When you load this script, the Fibonacci retracement tool will appear automatically on your chart. Because it uses the "visible window" logic, the lines will refresh and update dynamically as you scroll across different parts of the history or as new price candles form. This ensures that the levels are always relevant to the specific section of the market you are currently analyzing.

15 Views
0 Downloads
0 Favorites
XIT_FIBS_mod_1
ÿþ//+------------------------------------------------------------------+

//|                                               XIT_FIBS_mod_1.mq4 |

//|                        Copyright 2017, MetaQuotes Software Corp. |

//|                                             https://www.mql5.com |

//|                                                                  |

//| File45: Added Jan 2017                                           |

//| input color LC = DodgerBlue; // Fib Line Color                   |                   

//| input ENUM_LINE_STYLE LS = 2; // Fib Line Style                  |

//| input int LW = 1; // Fib Line Width                              |

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

//|                                                    XIT_FIBS.mq4  |

//|                         Copyright © 2011, Jeff West - Forex-XIT  |

//+------------------------------------------------------------------+

#property copyright "Copyright 2017, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property description "Automatically draws fibonacci retracements on chart." 

#property strict

#property indicator_chart_window



input color LC = DodgerBlue; // Fib Line Color 

input ENUM_LINE_STYLE LS = 2; // Fib Line Style

input int LW = 1; // Fib Line Width



color levelColor;



int OnInit()

  {   

   return(INIT_SUCCEEDED);

  }

  

void OnDeinit(const int reason)

  {

   ObjectDelete("XIT_FIBO");

  }    



int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

     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]);

       levelColor = LC;

     }

      else

     {

       WindowRedraw();

       ObjectCreate("XIT_FIBO",OBJ_FIBO,0,lowTime,Low[fibLow],highTime,High[fibHigh]);

       levelColor = LC;

     }

      

     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,LW);

     ObjectSet("XIT_FIBO",OBJPROP_LEVELSTYLE,LS);

     

     /*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%");*/

     

     ObjectSetFiboDescription( "XIT_FIBO",0, "0,0.0%"); 

     ObjectSetFiboDescription( "XIT_FIBO",1, "23.6%"); 

     ObjectSetFiboDescription( "XIT_FIBO",2, "38.2%"); 

     ObjectSetFiboDescription( "XIT_FIBO",3, "50.0%");

     ObjectSetFiboDescription( "XIT_FIBO",4, "61.8%");

     ObjectSetFiboDescription( "XIT_FIBO",5, "100.0%");

   

     return(rates_total);

  }

 

Comments