Log in to see Cloud of Tags

Wealth-Lab Wiki


public ATR(WealthLab.Bars bars, int period, string description)
public static ATR Series(WealthLab.Bars bars, int period)
public static double Value(int bar, WealthLab.Bars bars, int period)

Parameter Description

bars The Bars object
period Indicator calculation period


The Average True Range is the average of the true ranges over the specified Period. WealthScript uses the moving average as formulated by Welles Wilder, the indicator's inventor (see WilderMA and TrueRange). The ATR is a measure of volatility and it takes into account any gaps in the price movement. Typically the ATR calculation is based on 14 periods, this can be intraday, daily, weekly or monthly. To measure recent volatility use a shorter average, 2 to 10 periods. For longer term volatility use 20 to 50 periods.


  • An expanding ATR indicates increased volatility in the market. The range of each bar is getting larger. ATR often peaks at major tops and bottoms. High ATR values usually result from a sharp advance or decline and are unlikely to be sustained for extended periods.
  • A low average true range value indicates a series of periods with small ranges (quiet days). These low ATR values are often found during extended sideways price action, thus lower volatility. A prolonged period of low ATR values may indicate a consolidation area and the beginning of a continuation move or reversal.
  • ATR is very useful for stops or entry triggers, as it allows for changes in volatility. Whereas fixed dollar, points or percentage stops will not allow for volatility. The ATR stop will adapt to sharp price moves or consolidation areas, and trigger on an abnormal price movement in either area. Use a multiple of ATR, such as 1.5 x ATR(5 period) to catch these abnormal price moves.


Average True Range is calculated by applying Wilder's Moving Average to True Range over the period specified, see WilderMA indicator for more information:

ATR = ( Previous ATR * ( n - 1 ) + TR ) / n

ATR = Average True Range n = number of periods or bars TR = True Range, (see TrueRange indicator)


This simple system illustrates the application of the "ATR Ratchet" trailing exit created by Chuck LeBeau:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class RatchetStrategy : WealthScript { private StrategyParameter paramUnit; private StrategyParameter paramATR; private StrategyParameter paramLow; public RatchetStrategy() { paramUnit = CreateParameter("Unit", 0.05, 0.01, 0.1, 0.01); paramATR = CreateParameter("ATR period", 20, 2, 30, 2); paramLow = CreateParameter("Lowest low", 55, 5, 200, 5); } protected override void Execute() { int low = paramLow.ValueInt; int atr = paramATR.ValueInt; double unit = paramUnit.Value; DataSeries AtrRatchet = new DataSeries(Bars,"Ratchet"); PlotSeries(PricePane,AtrRatchet,Color.Red,LineStyle.Dots,4); for(int bar = GetTradingLoopStartBar(Math.Max(low,atr)); bar < Bars.Count; bar++) { AtrRatchet[bar] = Close[bar]; SetSeriesBarColor( bar, AtrRatchet, Color.Transparent ); if (IsLastPositionActive) { int daysintrade = bar - LastPosition.EntryBar; double ratchet = ( ATR.Series(Bars,atr)[bar] * unit ) * daysintrade; double sellprice = Lowest.Series(Low,low)[bar] + ratchet; AtrRatchet[bar] = sellprice; SetSeriesBarColor( bar, AtrRatchet, Color.Red );

if( Low[bar] < sellprice ) SellAtMarket(bar+1,LastPosition); } else { if(CrossOver(bar,Close,SMA.Series(Close,20))) BuyAtMarket(bar+1); } } } } }

This example plots ATRs in decreasing length if increasing blue intensity:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies { public class MyStrategy : WealthScript { // Thank you fundtimer public Color WS4ColorToNET( double WS4Color ) { return Color.FromArgb( (int)Math.Floor( ( WS4Color % 1000 ) / 100 * 28.4 ), (int)Math.Floor( ( WS4Color % 100 ) / 10 * 28.4 ), (int)Math.Floor( WS4Color % 10 * 28.4 ) ); } protected override void Execute() { // Plot ATRs in decreasing length if increasing blue intensity ChartPane ATRPane = CreatePane( 50, true, true ); DrawLabel( ATRPane, "ATR from 2 to 18", Color.Black ); for( int i = 1; i < 10; i++ ) PlotSeries( ATRPane, ATR.Series( Bars, i * 2 ), WS4ColorToNET(10-i), LineStyle.Solid, 1 ); } } }

Important Disclaimer: The information provided by Wealth-Lab is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security.  The owner of Wealth-Lab.com assumes no liability resulting from the use of the material contained herein for investment purposes. By using this web site, you agree to the terms of this disclaimer and our Terms of Use.

ScrewTurn Wiki. Some of the icons created by FamFamFam.