ATRChannel
Download scriptThis tool is designed to provide traders with a visual representation of market volatility by plotting a dynamic "channel" on your trading chart. It helps identify the boundaries of price movement based on historical price swings.
Core Logic and Functionality
The script works by calculating two distinct boundary lines—an upper and a lower channel—that expand and contract in real-time according to how much the market is moving. Here is how the logic flows:
1. Measuring Volatility (ATR) The primary engine of this tool is the Average True Range (ATR). Instead of just looking at where the price is, the script looks at how much the price has been fluctuating over a specific period (defaulting to 14 bars). This "volatility score" determines how wide or narrow the channel will be.
2. Establishing the Price Base Depending on your preference, the script chooses one of two ways to anchor these boundaries:
- Standard Mode: The script takes the highest price and the lowest price of a specific candle. It then projects the volatility boundaries outward from those extremes.
- Median Mode: If enabled, the script finds the exact midpoint between the high and low of a candle and uses that center point to project the upper and lower boundaries equally in both directions.
3. Dynamic Drawing The tool calculates these values for every bar on your chart.
- The Upper Channel is created by adding the volatility score to the base price.
- The Lower Channel is created by subtracting the volatility score from the base price.
Key User Controls
- Calculation Timing: You can choose whether the indicator updates instantly as new price ticks come in or waits until a candle has officially closed before finalizing the calculation.
- Price Reference: You can toggle between using the extreme highs/lows of the candles for your boundaries or using the calculated midpoint (median) of those candles.
- Sensitivity: By adjusting the period, you can change how much historical data the script considers when measuring volatility; a shorter period reacts faster to sudden moves, while a longer period provides a smoother, more stable channel.
In summary, this script visualizes "normal" market behavior. When the price stays within these channels, it is moving within expected volatility; when it breaks out significantly, it may indicate a shift in market momentum.
//+------------------------------------------------------------------+
//| ATRChannel.mq4
//| Copyright © Pointzero-indicator.com
//+------------------------------------------------------------------+
#property copyright "Copyright © Pointzero-indicator.com"
#property link "http://www.pointzero-indicator.com"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 DodgerBlue
//---- indicator parameters
extern bool CalculateOnBarClose = true;
extern bool UseMedianPrice = false;
extern int ATRPeriod = 14;
//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
// Drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
// Name and labels
IndicatorShortName("ATRChannel");
SetIndexLabel(0,"Upper Channel");
SetIndexLabel(1,"Lower Channel");
// Buffers
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
Comment("Copyright © http://www.pointzero-indicator.com");
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
// Start, limit, etc..
int start = 0;
int limit;
int counted_bars = IndicatorCounted();
// check for possible errors
if(counted_bars < 0)
return(-1);
// Only check these
limit = Bars - 1 - counted_bars;
// Check if ignore bar 0
if(CalculateOnBarClose == true) start = 1;
// Check the signal foreach bar
for(int i = limit; i >= start; i--)
{
// Median
double high = iHigh(Symbol(), 0, i);
double low = iLow(Symbol(), 0, i);
double median = (high + low) / 2;
// Atr
double atr = iATR(Symbol(), 0, ATRPeriod, i);
// Draw
if(UseMedianPrice)
{
ExtMapBuffer1[i] = median + atr;
ExtMapBuffer2[i] = median - atr;
} else {
ExtMapBuffer1[i] = high + atr;
ExtMapBuffer2[i] = low - atr;
}
}
// Bye Bye
return(0);
}
//+------------------------------------------------------------------+
Comments