This tool is designed to provide traders with a visual map of price behavior by calculating and displaying specific boundaries on a trading chart. It works by identifying the "heartbeat" of the market—the average trend—and then measuring how far the current price deviates from that average.
How the Logic Works
The script operates based on three primary components that work together to create a clear visual corridor for the user:
1. Identifying the Core Trend (The Baseline) First, the tool looks at a specific number of past price points (defined by the "Period" setting). It calculates the Simple Moving Average (SMA) of these prices. This represents the "equilibrium" or the center line of the market's current movement.
2. Measuring Market Volatility (The Standard Deviation) Once the center line is established, the script analyzes how much the price has been swinging away from that average. It calculates what is known as the "Standard Deviation." Essentially, it determines if the market is currently calm (with prices staying close to the average) or volatile (with prices making large swings).
3. Establishing Dynamic Boundaries This is where the tool provides its unique value. Instead of using a standard measurement, it multiplies that volatility by a specific "Deviation" coefficient. It then projects two boundaries:
- The Upper Boundary: Calculated by adding the deviation to the average.
- The Lower Boundary: Calculated by subtracting the deviation from the average.
Practical Application
By plotting these three lines on your chart, the script creates a dynamic "channel." Because both the center line and the boundaries are recalculated with every new price update, the channel expands when the market becomes volatile and contracts when the market stabilizes.
For a trader, this provides a clear visual representation of what constitutes an "extreme" price move relative to current market conditions, helping to identify potential overbought or oversold zones based on the specific volatility of the moment.
//+------------------------------------------------------------------+
//| BBwithFractdev.mq4 |
//| Êèì Èãîðü Â. aka KimIV |
//| http://www.kimiv.ru |
//| |
//| Ïîëîñû Áîëëèíäæåðà ñ äðîáíûì êîýôôèöèåíòîì îòêëîíåíèÿ |
//+------------------------------------------------------------------+
#property copyright "Êèì Èãîðü Â. aka KimIV"
#property link "http://www.kimiv.ru"
//----
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_color2 Blue
#property indicator_color3 Green
//---- input parameters
extern int BB_Period=13; // Ïåðèîä ñðåäíåé è îòêëîíåíèÿ
extern double Deviation=2.618; // Êîýôôèöèåíò îòêëîíåíèÿ
//---- indicator buffers
double buf1[];
double buf2[];
double buf3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void init()
{
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_LINE);
IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
//----
SetIndexBuffer(0, buf1);
SetIndexBuffer(1, buf2);
SetIndexBuffer(2, buf3);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
void start()
{
int i, j;
double ave, sko, sum;
if (Bars<=BB_Period) return;
for(i=Bars-BB_Period; i>=0; i--)
{
buf2[i]=iMA(NULL,0,BB_Period,0,MODE_SMA,PRICE_CLOSE,i);
sum=0;
for(j=0; j<BB_Period; j++) sum+=Close[i+j];
ave=sum/BB_Period;
sum=0;
for(j=0; j<BB_Period; j++) sum+=(Close[i+j]-ave)*(Close[i+j]-ave);
sko=MathSqrt(sum/BB_Period);
buf1[i]=buf2[i]+(Deviation*sko);
buf3[i]=buf2[i]-(Deviation*sko);
}
}
//+------------------------------------------------------------------+
Comments