^X_Fibo
Download scriptThis script is designed for the MetaTrader platform to automatically project key price levels on your trading chart based on historical data from previous trading periods. It simplifies technical analysis by instantly identifying potential support and resistance zones without requiring the user to calculate them manually.
Core Functionality
The primary logic of this script revolves around capturing the high and low prices of a completed prior period (such as a Day, Week, or Month) and using those coordinates to draw dynamic visual aids on your current chart.
1. Smart Timeframe Adaptation
The script includes an "Automation" mode. When enabled, it detects which timeframe you are currently viewing and automatically adjusts its internal settings:
- If you are viewing a high-level chart (greater than 4 hours), it focuses on Monthly data.
- If you are viewing a low-level chart (less than 4 hours), it focuses on Daily data.
- Otherwise, it defaults to Weekly data. This ensures that the visual levels remain relevant and consistent regardless of how much you zoom in or out on your price action.
2. Key Visual Components
The script automatically generates and manages three distinct sets of visual markers:
- Price Boundaries (Top & Bottom): It draws two solid horizontal lines representing the exact High and Low prices of the previous period. These serve as the immediate boundaries for current price movement.
- Fibonacci Projections (FU & FD): The script calculates the total price range (the distance between the high and low) and projects "Fibonacci Extension" levels. These are dashed lines that extend beyond the previous high and low, helping traders identify potential targets or "over-extended" zones in the future.
- Fibonacci Retracement (FR): A gold-colored set of levels is mapped between the previous period's high and low. This helps identify key psychological areas where the price might pull back or find support during a trend.
3. Dynamic Updates
The logic is programmed to be "event-aware." Instead of constantly taxing your computer's resources, it only performs its calculations when a new candle forms or if you switch timeframes. It then instantly repositions all lines and Fibonacci levels to correspond with the most recent historical data available.
4. Clean Workspace Management
The script is designed to be non-intrusive. When you remove the script from your chart, it includes a "deinitialization" process that automatically deletes all the lines and objects it created, leaving your workspace clean.
#property indicator_chart_window
extern bool _Automate = true;
extern string _My_Period_Data = "1440=D1; 10080=W1; 43200=MN";
extern int _My_Period = PERIOD_W1;
int _N_Time, _Cur_Period;
//-------------------------------------------------------------------------------------------
int init() {
if(!_Automate) {
if(Period() > _My_Period) {
Comment("\n\n ERROR - CHART PERIOD IS TOO GREAT!");
return(-1); // then exit
}} else {
if(Period() > PERIOD_H4) _My_Period = PERIOD_MN1;
else if(Period() < PERIOD_H4) _My_Period = PERIOD_D1;
else _My_Period = PERIOD_W1;
}
ObjectCreate ("TOP", OBJ_HLINE, 0, Time[0], 0);
ObjectSet ("TOP", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet ("TOP", OBJPROP_WIDTH, 1);
ObjectSet ("TOP", OBJPROP_COLOR, Orange);
ObjectCreate ("FU", OBJ_FIBO, 0, Time[89], 0, Time[89], 0);
ObjectSet ("FU", OBJPROP_LEVELSTYLE, STYLE_DASH);
ObjectSet ("FU", OBJPROP_LEVELWIDTH, 1);
ObjectSet ("FU", OBJPROP_LEVELCOLOR, Orange);
ObjectSet ("FU", OBJPROP_FIBOLEVELS, 10);
ObjectSet ("FU", OBJPROP_FIRSTLEVEL+0, 0.236);
ObjectSetFiboDescription("FU",0,"+23.6 ");
ObjectSet ("FU", OBJPROP_FIRSTLEVEL+1, 0.382);
ObjectSetFiboDescription("FU",1,"+38.2 ");
ObjectSet ("FU", OBJPROP_FIRSTLEVEL+2, 0.5);
ObjectSetFiboDescription("FU",2,"+50.0 ");
ObjectSet ("FU", OBJPROP_FIRSTLEVEL+3, 0.618);
ObjectSetFiboDescription("FU",3,"+61.8 ");
ObjectSet ("FU", OBJPROP_FIRSTLEVEL+4, 0.764);
ObjectSetFiboDescription("FU",4,"+76.4 ");
ObjectSet ("FU", OBJPROP_FIRSTLEVEL+5, 1.0);
ObjectSetFiboDescription("FU",5,"+100.0 ");
ObjectSet ("FU", OBJPROP_FIRSTLEVEL+6, 1.236);
ObjectSetFiboDescription("FU",6,"+123.6 ");
ObjectSet ("FU", OBJPROP_FIRSTLEVEL+7, 1.382);
ObjectSetFiboDescription("FU",7,"+138.2 ");
ObjectSet ("FU", OBJPROP_FIRSTLEVEL+8, 1.5);
ObjectSetFiboDescription("FU",8,"+150.0 ");
ObjectSet ("FU", OBJPROP_FIRSTLEVEL+9, 1.618);
ObjectSetFiboDescription("FU",9,"+161.8 ");
ObjectCreate ("BOTTOM", OBJ_HLINE, 0, Time[0], 0);
ObjectSet ("BOTTOM", OBJPROP_STYLE, STYLE_SOLID);
ObjectSet ("BOTTOM", OBJPROP_WIDTH, 1);
ObjectSet ("BOTTOM", OBJPROP_COLOR, DeepSkyBlue);
ObjectCreate ("FD", OBJ_FIBO, 0, Time[89], 0, Time[89], 0);
ObjectSet ("FD", OBJPROP_LEVELSTYLE, STYLE_DASH);
ObjectSet ("FD", OBJPROP_LEVELWIDTH, 1);
ObjectSet ("FD", OBJPROP_LEVELCOLOR, DeepSkyBlue);
ObjectSet ("FD", OBJPROP_FIBOLEVELS, 10);
ObjectSet ("FD", OBJPROP_FIRSTLEVEL+0, 0.236);
ObjectSetFiboDescription("FD",0,"-23.6 ");
ObjectSet ("FD", OBJPROP_FIRSTLEVEL+1, 0.382);
ObjectSetFiboDescription("FD",1,"-38.2 ");
ObjectSet ("FD", OBJPROP_FIRSTLEVEL+2, 0.5);
ObjectSetFiboDescription("FD",2,"-50.0 ");
ObjectSet ("FD", OBJPROP_FIRSTLEVEL+3, 0.618);
ObjectSetFiboDescription("FD",3,"-61.8 ");
ObjectSet ("FD", OBJPROP_FIRSTLEVEL+4, 0.764);
ObjectSetFiboDescription("FD",4,"-76.4 ");
ObjectSet ("FD", OBJPROP_FIRSTLEVEL+5, 1.0);
ObjectSetFiboDescription("FD",5,"-100.0 ");
ObjectSet ("FD", OBJPROP_FIRSTLEVEL+6, 1.236);
ObjectSetFiboDescription("FD",6,"-123.6 ");
ObjectSet ("FD", OBJPROP_FIRSTLEVEL+7, 1.382);
ObjectSetFiboDescription("FD",7,"-138.2 ");
ObjectSet ("FD", OBJPROP_FIRSTLEVEL+8, 1.5);
ObjectSetFiboDescription("FD",8,"-150.0 ");
ObjectSet ("FD", OBJPROP_FIRSTLEVEL+9, 1.618);
ObjectSetFiboDescription("FD",9,"-161.8 ");
ObjectCreate ("FR", OBJ_FIBO, 0, Time[89], 0, Time[89], 0);
ObjectSet ("FR", OBJPROP_LEVELSTYLE, STYLE_DASH);
ObjectSet ("FR", OBJPROP_LEVELWIDTH, 1);
ObjectSet ("FR", OBJPROP_LEVELCOLOR, Gold);
ObjectSet ("FR", OBJPROP_FIBOLEVELS, 5);
ObjectSet ("FR", OBJPROP_FIRSTLEVEL+0, 0.236);
ObjectSetFiboDescription("FR",0,"23.6 ");
ObjectSet ("FR", OBJPROP_FIRSTLEVEL+1, 0.382);
ObjectSetFiboDescription("FR",1,"38.2 ");
ObjectSet ("FR", OBJPROP_FIRSTLEVEL+2, 0.5);
ObjectSetFiboDescription("FR",2,"50.0 ");
ObjectSet ("FR", OBJPROP_FIRSTLEVEL+3, 0.618);
ObjectSetFiboDescription("FR",3,"61.8 ");
ObjectSet ("FR", OBJPROP_FIRSTLEVEL+4, 0.764);
ObjectSetFiboDescription("FR",4,"76.4 ");
_N_Time = 0;
_Cur_Period = 0;
return(0);
}
//-------------------------------------------------------------------------------------------
int deinit() {
ObjectDelete("FU");
ObjectDelete("FD");
ObjectDelete("FR");
ObjectDelete("TOP");
ObjectDelete("BOTTOM");
Comment(" ");
return(0);
}
//-------------------------------------------------------------------------------------------
int start() {
if( (_N_Time != Time[0]) || (_Cur_Period != Period()) ) {
//=================================================================
double yesterday_high, yesterday_low, yesterday_close, Q, _X_Point;
double rates_mn[2][6];
ArrayCopyRates(rates_mn, Symbol(), _My_Period);
yesterday_high = rates_mn[1][3];
yesterday_low = rates_mn[1][2];
yesterday_close = rates_mn[1][4];
Q = yesterday_high - yesterday_low;
ObjectMove ("TOP", 0, Time[0], yesterday_high);
ObjectMove ("BOTTOM", 0, Time[0], yesterday_low);
ObjectMove ("FU", 0, Time[89], yesterday_high + Q);
ObjectMove ("FU", 1, Time[89], yesterday_high);
ObjectMove ("FD", 1, Time[89], yesterday_low);
ObjectMove ("FD", 0, Time[89], yesterday_low - Q);
ObjectMove ("FR", 0, Time[89], yesterday_high);
ObjectMove ("FR", 1, Time[89], yesterday_low);
_N_Time = Time[0];
_Cur_Period = Period();
//=================================================================
}
return(0);
}
//-------------------------------------------------------------------------------------------
Comments