Bands+Fibo_True
Download scriptThe Bands+Fibo indicator is a visual analysis tool designed to help traders identify potential price boundaries and volatility trends on a trading chart. It combines two well-known market concepts—Bollinger Bands logic and Fibonacci retracement levels—into a single, cohesive visual layout.
Core Logic Overview
The script functions by calculating a "baseline" of current market activity and then projectively expanding outward to create various support and resistance zones. Here is how the logic flows:
1. Establishing the Baseline (Moving Average) The indicator first calculates a Simple Moving Average (SMA). This acts as the "center line," representing the average price over a specific number of previous candles. It provides a smoothed view of the market's direction, helping to filter out minor price fluctuations.
2. Measuring Volatility (ATR) To determine how wide the bands should be, the script uses an Average True Range (ATR) calculation. This measures the recent "mood" of the market—specifically, how much the price has been swinging up and down. By using this measurement, the indicator ensures that the bands widen during high-volatility periods and tighten during quiet markets.
3. Fibonacci Expansion Levels The unique feature of this script is how it applies the results of the moving average and volatility to Fibonacci proportions. Instead of using standard fixed multipliers, it multiplies the volatility (ATR) by three specific Fibonacci levels:
- 1.618
- 2.618
- 4.236
The script then applies these multipliers both above and below the moving average baseline.
Visual Representation on Your Chart
When you apply this to a chart, you will see a multi-layered system of lines:
- The Centerline: A dotted line representing the average price movement.
- The Inner Bands (1.618): These represent the immediate "breathing room" for the price. They are often used to identify standard fluctuations.
- The Outer Bands (2.618 & 4.236): These represent significant extreme zones. Because these levels are based on Fibonacci ratios, they are often used by traders to identify potential exhaustion points where a price might stall, reverse, or enter a period of consolidation.
Summary for the Trader
This tool provides a dynamic "map" of the market. Because it adjusts automatically based on current volatility (via ATR) and follows mathematical proportions (Fibonacci), it helps you visualize where the price is currently "oversold" or "overbought" relative to its recent history, allowing for more structured entry and exit planning.
//+------------------------------------------------------------------+
//| Bands+Fibo.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Blue
#property indicator_color2 Green
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_color5 LightSeaGreen
#property indicator_color6 Red
#property indicator_color7 LightSeaGreen
//---- indicator parameters
extern int BandsPeriod=20;
extern int BandsShift=0;
extern int PeriodsATR= 20;
//---- buffers
double MovingBuffer[];
double UpperBuffer[];
double UpperBuffer2[];
double UpperBuffer3[];
double LowerBuffer[];
double LowerBuffer2[];
double LowerBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(0,MovingBuffer);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(1,UpperBuffer);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(2,LowerBuffer);
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(3,UpperBuffer2);
SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(4,UpperBuffer3);
SetIndexStyle(5,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(5,LowerBuffer2);
SetIndexStyle(6,DRAW_LINE,STYLE_SOLID,2);
SetIndexBuffer(6,LowerBuffer3);
//----
SetIndexDrawBegin(0,BandsPeriod+BandsShift);
SetIndexDrawBegin(1,BandsPeriod+BandsShift);
SetIndexDrawBegin(2,BandsPeriod+BandsShift);
SetIndexDrawBegin(3,BandsPeriod+BandsShift);
SetIndexDrawBegin(4,BandsPeriod+BandsShift);
SetIndexDrawBegin(5,BandsPeriod+BandsShift);
SetIndexDrawBegin(6,BandsPeriod+BandsShift);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Bollinger Bands |
//+------------------------------------------------------------------+
int start()
{
int i,k,counted_bars=IndicatorCounted();
double deviation;
double sum,oldval,newres;
//----
if(Bars<=BandsPeriod) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=BandsPeriod;i++)
{
MovingBuffer[Bars-i]=EMPTY_VALUE;
UpperBuffer[Bars-i]=EMPTY_VALUE;
UpperBuffer2[Bars-i]=EMPTY_VALUE;
UpperBuffer3[Bars-i]=EMPTY_VALUE;
LowerBuffer[Bars-i]=EMPTY_VALUE;
LowerBuffer2[Bars-i]=EMPTY_VALUE;
LowerBuffer3[Bars-i]=EMPTY_VALUE;
}
//----
int limit=Bars-counted_bars;
if(counted_bars>0) limit++;
for(i=0; i<limit; i++)
MovingBuffer[i]=iMA(NULL,0,BandsPeriod,BandsShift,MODE_SMA,PRICE_CLOSE,i);
//----
i=Bars-BandsPeriod+1;
if(counted_bars>BandsPeriod-1) i=Bars-counted_bars-1;
while(i>=0)
{
sum=0.0;
k=i+BandsPeriod-1;
oldval=MovingBuffer[i];
deviation=iATR(NULL,0,PeriodsATR,i);
UpperBuffer[i]=oldval+deviation*1.618;
UpperBuffer2[i]=oldval+deviation*2.618;
UpperBuffer3[i]=oldval+deviation*4.236;
LowerBuffer[i]=oldval-deviation*1.618;
LowerBuffer2[i]=oldval-deviation*2.618;
LowerBuffer3[i]=oldval-deviation*4.236;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments