Skip to content

IIndicatorsAccessor.AverageTrueRange

method · IIndicatorsAccessor · cAlgo.API.Internals

DesktopCLICloud

Average true range. An indicator providing the degree of price volatility.

Overloads

AverageTrueRange(int periods, MovingAverageType maType)

Average true range. An indicator providing the degree of price volatility.

AverageTrueRange AverageTrueRange(int periods, MovingAverageType maType)
api.Indicators.AverageTrueRange(periods: int, maType: MovingAverageType) -> AverageTrueRange

Parameters

Name C# type Python type Description
periods int int Period of moving average to use for Average True Range caluclation.
maType MovingAverageType MovingAverageType Type of moving average to use for Average True Range caluclation.

Returns AverageTrueRange — Average True Range indicator instance

Examples

var atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
var stopLossPips = 2 * atr.Result.LastValue / Symbol.PipSize;
Print("ATR(14): {0}, stop loss at 2 x ATR: {1} pips", atr.Result.LastValue, stopLossPips);
atr = api.Indicators.AverageTrueRange(14, MovingAverageType.Exponential)
stopLossPips = 2 * atr.Result.LastValue / api.Symbol.PipSize
api.Print(f"ATR(14): {atr.Result.LastValue}, stop loss at 2 x ATR: {stopLossPips} pips")

AverageTrueRange(Bars bars, int periods, MovingAverageType maType)

Average true range. An indicator providing the degree of price volatility.

AverageTrueRange AverageTrueRange(Bars bars, int periods, MovingAverageType maType)
api.Indicators.AverageTrueRange(bars: Bars, periods: int, maType: MovingAverageType) -> AverageTrueRange

Parameters

Name C# type Python type Description
bars Bars Bars The Bars that will be used by indicator, you can pass another timeframe/symbol bars
periods int int Period of moving average to use for Average True Range caluclation.
maType MovingAverageType MovingAverageType Type of moving average to use for Average True Range caluclation.

Returns AverageTrueRange — Average True Range indicator instance

Examples

var dailyBars = MarketData.GetBars(TimeFrame.Daily);
var dailyAtr = Indicators.AverageTrueRange(dailyBars, 14, MovingAverageType.Exponential);
Print("Daily ATR(14): {0} pips", dailyAtr.Result.LastValue / Symbol.PipSize);
dailyBars = api.MarketData.GetBars(TimeFrame.Daily)
dailyAtr = api.Indicators.AverageTrueRange(dailyBars, 14, MovingAverageType.Exponential)
api.Print(f"Daily ATR(14): {dailyAtr.Result.LastValue / api.Symbol.PipSize} pips")