Building Trading Strategies Indicators Average True Range

Average True Range

AverageTrueRange is a market volatility indicator. High ATR values may signal market bottoms often accompanied by panic selling, while low ATR values might indicate prolonged sideways movements or consolidation phases, typical at market tops.

Market Signals

Forecasting with ATR goes like this: a higher ATR suggests a potential trend change, whereas a lower ATR implies a weaker trend movement.

Calculation

The ATR is calculated using a modified Moving Average (MMA) of the true range, which is the maximum of the current high less the current low, and the absolute value of the current high less the previous close or the current low less the previous close.

ATR = MMA[Max(High_i, Close_iāˆ’1) āˆ’ Min(Low_i, Close_iāˆ’1), Period]

ATR takes into account the range of price movement in a given period, smoothing out the data to provide a clearer view of volatility trends.

    import { Bar, InstrumentProcessorBase } from '@botmain/common';
    import { ExponentialMovingAverage } from '@botmain/indicators';

    export class InstrumentProcessor extends InstrumentProcessorBase {
        ema = new ExponentialMovingAverage(14);

        periodBasedAtr = new AverageTrueRange(28);
        exponentialBasedAtr = new AverageTrueRange(this.ema);

        ...

        onBarClose(bar: Bar) {
            //Add bar close to calculate new average true range
            this.ema.add(bar.close);

            periodBasedAtr.addBar(bar);
            exponentialBasedAtr.addBar(bar);

            ...

            if(exponentialBasedAtr.last > someVolatilityThreshold) {
                ...
            }
        }
    }