autofibo
Download scriptThis tool is designed to automatically identify and display Fibonacci retracement levels on your trading chart based on specific price action history. Instead of requiring you to manually select highs and lows, the script dynamically calculates these key points in real-time.
Core Functionality
The primary purpose of this script is to automate the placement of a Fibonacci tool by analyzing a set window of recent market data. It looks back over a defined period (customizable by the user) to find the most significant price boundaries, ensuring that the retracement levels are always anchored to relevant historical peaks and valleys.
Key Logic Components
Dynamic Range Identification The script continuously scans the market to determine the "High" and "Low" points within your chosen timeframe. It does this by evaluating every candle within the look-back period to find the absolute extremes. You can choose whether the logic should prioritize the actual "High/Low" wicks of the candles or the "Open/Close" body prices, depending on your preferred trading style.
Automated Orientation One of the script's intelligent features is its ability to detect market direction. It compares current price action against historical data to decide which way the Fibonacci tool should point:
- If the market shows an upward trend, it anchors the tool to reflect a potential retracement from a previous high.
- If the market shows a downward trend, it automatically flips the orientation to reflect a retracement from a previous low.
Real-Time Updating The script is designed to be "live." As new price data arrives with every tick, the indicator recalculates the boundaries and moves the Fibonacci object automatically. This ensures that your retracement levels stay synchronized with the most recent market movement without any manual intervention.
User Experience
For a trader, this means the visual layout of your chart stays organized and updated. Rather than drawing and redrawing lines every time the price moves, the script handles the "heavy lifting" of scanning history and updating the coordinates, allowing you to focus on identifying trade entries based on the automatically generated levels.
#property copyright "Copyright © 2009, Julien Loutre"
#property link "http://www.forexcomm.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LightSkyBlue
#property indicator_color2 Plum
extern int Band_Period = 48;
extern int price_type = 0; // 0 = High/Low | 1 = Open/Close
//---- buffers
double WWBuffer1[];
double WWBuffer2[];
double WWBuffer3[];
double ATR;
int init() {
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_LINE,1);
SetIndexStyle(1,DRAW_LINE,1);
SetIndexLabel(0, "High");
SetIndexLabel(1, "Low");
SetIndexBuffer(0, WWBuffer1);
SetIndexBuffer(1, WWBuffer2);
IndicatorDigits(Digits+2);
IndicatorShortName("Automatic Fibonacci");
ObjectCreate("AutoFibo", OBJ_FIBO, 0, Time[0],High[0],Time[0],Low[0]);
return(0);
}
int deinit() {
ObjectDelete("AutoFibo");
}
int start() {
int counted_bars=IndicatorCounted();
int limit,i;
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for(i=limit-1; i>=0; i--) {
WWBuffer1[i] = getPeriodHigh(Band_Period,i);
WWBuffer2[i] = getPeriodLow(Band_Period,i);
ObjectSet("AutoFibo", OBJPROP_TIME1, Time[Band_Period]);
ObjectSet("AutoFibo", OBJPROP_TIME2, Time[0]);
if (Open[Band_Period] < Open[0]) { // Up
ObjectSet("AutoFibo", OBJPROP_PRICE1, getPeriodHigh(Band_Period,i));
ObjectSet("AutoFibo", OBJPROP_PRICE2, getPeriodLow(Band_Period,i));
} else {
ObjectSet("AutoFibo", OBJPROP_PRICE1, getPeriodLow(Band_Period,i));
ObjectSet("AutoFibo", OBJPROP_PRICE2, getPeriodHigh(Band_Period,i));
}
}
return(0);
}
double getPeriodHigh(int period, int pos) {
int i;
double buffer = 0;
for (i=pos;i<=pos+period;i++) {
if (price_type == 0) {
if (High[i] > buffer) {
buffer = High[i];
}
} else {
if (Open[i] > Close[i]) { // Down
if (Open[i] > buffer) {
buffer = Open[i];
}
} else {
if (Close[i] > buffer) {
buffer = Close[i];
}
}
}
}
return (buffer);
}
double getPeriodLow(int period, int pos) {
int i;
double buffer = 100000;
for (i=pos;i<=pos+period;i++) {
if (price_type == 0) {
if (Low[i] < buffer) {
buffer = Low[i];
}
} else {
if (Open[i] > Close[i]) { // Down
if (Close[i] < buffer) {
buffer = Close[i];
}
} else {
if (Open[i] < buffer) {
buffer = Open[i];
}
}
}
}
return (buffer);
}
Comments