MT4 ATR Volatility Breakout Indicator: Confirmed-Bar MQL4 Code
ATR measures the size of price movement, not its direction. This original MT4 indicator plots a volatility envelope anchored to the previous completed candle and marks a breakout only after a candle closes beyond that envelope. It is designed as an educational signal study, not an automatic trading system.
Exact signal calculations
For candle i, upper threshold = Close[i+1] + 1.6 × ATR(14)[i+1]; lower threshold = Close[i+1] − 1.6 × ATR(14)[i+1]. ATR uses true range: max(High−Low, absolute High−previous Close, absolute Low−previous Close), then smoothing through the platform's built-in iATR implementation. A bullish arrow appears when Close[i] exceeds the upper threshold; a bearish arrow appears when Close[i] falls below the lower threshold. The optional body confirmation requires a bullish or bearish candle respectively. Both the reference close and ATR are from the preceding completed candle, so no future bar is needed.
Illustration

Numerical walkthrough
If the previous completed candle closed at 1.1000 with ATR(14) of 0.0020, the upper threshold at 1.6 ATR is 1.1032 and the lower threshold is 1.0968. A following bullish candle that closes at 1.1036 triggers a bullish arrow after it closes. An intrabar spike above 1.1032 followed by a close at 1.1029 does not. This distinction reduces signals based on temporary intrabar moves.
Complete MT4 custom indicator
Save as MT4_ATR_Band_Breakout.mq4 under MQL4/Indicators. The four output buffers store upper and lower levels plus bullish and bearish arrows. They are not EA orders.
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 clrDodgerBlue
#property indicator_color2 clrOrange
#property indicator_color3 clrLimeGreen
#property indicator_color4 clrTomato
input int ATRPeriod = 14;
input double ATRMultiplier = 1.6;
input int MaxBarsToCalculate = 1500; // 0 = all eligible history
input bool RequireBodyConfirmation = true;
double UpperBand[], LowerBand[], BuyArrow[], SellArrow[];
int OnInit()
{
if(ATRPeriod < 1 || ATRMultiplier <= 0 || MaxBarsToCalculate < 0)
return(INIT_PARAMETERS_INCORRECT);
SetIndexBuffer(0, UpperBand);
SetIndexBuffer(1, LowerBand);
SetIndexBuffer(2, BuyArrow);
SetIndexBuffer(3, SellArrow);
ArraySetAsSeries(UpperBand, true);
ArraySetAsSeries(LowerBand, true);
ArraySetAsSeries(BuyArrow, true);
ArraySetAsSeries(SellArrow, true);
SetIndexStyle(0, DRAW_LINE, STYLE_DASH, 1, clrDodgerBlue);
SetIndexStyle(1, DRAW_LINE, STYLE_DASH, 1, clrOrange);
SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 1, clrLimeGreen);
SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 1, clrTomato);
SetIndexArrow(2, 233);
SetIndexArrow(3, 234);
for(int j=0; j<4; j++) SetIndexEmptyValue(j, EMPTY_VALUE);
SetIndexLabel(0, "Previous close + ATR multiple");
SetIndexLabel(1, "Previous close - ATR multiple");
SetIndexLabel(2, "Confirmed bullish breakout");
SetIndexLabel(3, "Confirmed bearish breakout");
IndicatorShortName("Confirmed ATR Breakout");
return(INIT_SUCCEEDED);
}
int OnCalculate(const int rates_total, const int prev_calculated,
const datetime &time[], const double &open[],
const double &high[], const double &low[],
const double &close[], const long &tick_volume[],
const long &volume[], const int &spread[])
{
if(rates_total < ATRPeriod + 4) return(0);
ArraySetAsSeries(open, true);
ArraySetAsSeries(high, true);
ArraySetAsSeries(low, true);
ArraySetAsSeries(close, true);
// Never plot on the unfinished candle.
UpperBand[0] = LowerBand[0] = EMPTY_VALUE;
BuyArrow[0] = SellArrow[0] = EMPTY_VALUE;
int oldest = rates_total - ATRPeriod - 2;
if(MaxBarsToCalculate > 0) oldest = MathMin(oldest, MaxBarsToCalculate);
for(int i=oldest; i>=1; i--)
{
UpperBand[i] = LowerBand[i] = EMPTY_VALUE;
BuyArrow[i] = SellArrow[i] = EMPTY_VALUE;
// The threshold uses ONLY the previous closed candle.
double a = iATR(NULL, 0, ATRPeriod, i+1);
if(a <= 0) continue;
double top = close[i+1] + ATRMultiplier*a;
double bottom = close[i+1] - ATRMultiplier*a;
UpperBand[i] = top;
LowerBand[i] = bottom;
bool bullish = close[i] > top &&
(!RequireBodyConfirmation || close[i] > open[i]);
bool bearish = close[i] < bottom &&
(!RequireBodyConfirmation || close[i] < open[i]);
if(bullish) BuyArrow[i] = low[i] - 0.2*a;
if(bearish) SellArrow[i] = high[i] + 0.2*a;
}
return(rates_total);
}
Inputs and tuning
| Input | Default | Meaning |
|---|---|---|
| ATRPeriod | 14 | ATR lookback |
| ATRMultiplier | 1.6 | Distance from prior close, in ATR units |
| MaxBarsToCalculate | 1500 | Historical work cap; 0 means all eligible bars |
| RequireBodyConfirmation | true | Require directional candle body |
A smaller multiplier typically creates more signals but more noise. A longer ATR period smooths changes in volatility but reacts more slowly. These defaults are examples, not optimized parameters.
Installation and verification
- In MT4, open File → Open Data Folder → MQL4 → Indicators.
- Save the code, open it in MetaEditor and compile; inspect any warnings.
- Refresh Navigator, attach it to a chart with sufficient history, and inspect its Inputs.
- Confirm bar 0 has no arrow or band: the script deliberately plots completed bars only.
- Test symbols, timeframes, historical gaps and broker feeds; compare logged forward signals with historical arrows.
Limitations and risk
These are volatility breakouts, not guaranteed trend reversals or profitable entries. Ranging markets, news spikes and gaps can generate false signals. The code does not execute trades, set stops, size positions, or account for spread, commission and slippage. Broker history corrections may change historical plots even though future candles are not intentionally referenced. Always check nearby support/resistance and actual reward-to-risk before considering a trade.
For EA integration, production alerts or tailored indicator buffers, see Custom Trading Software Development Services.
Disclosure: Educational material only; not investment advice or a performance claim. API structure has been checked against official MQL4 documentation; this exact code has not been compiled or backtested in a terminal.