Average True Range Indicator
Send Feedback

Glossary Item Box

Topic Overview


This topic provides an overview of the Average True Range indicator in the IGChartView™ control and uses a code example to demonstrate how to add it to the chart view.

In this topic


Average True Range indicator summary

The IGChartView’s average true range indicator is a financial indicator that measures a security's degree of price movement or volatility within a given interval. The indicator is not a measure of price direction or duration, but simply the amount of price movement or volatility. The average true range (ATR) is frequently calculated with a 14 day period using several bases, including: daily, weekly or monthly. The average true range is the exponential moving average of the TR values for the last 14 periods. The actual period used can vary depending on the user’s preference.

Data requirements

While the IGChartView control allows easy binding to your own data model, make sure to supply the appropriate amounts and types of data required by the series. If the data does not meet the minimum requirements, based on the type of series that you are using, the IGChartView will appear blank.

The following is a list of data requirements for the average true range indicator type:

  • High (numeric)
  • Low (numeric)
  • Close (numeric)

Adding an Average True Range Indicator to the IGChartView – Code Example


The code below uses the IGOHLCSeriesDataSourceHelper to supply randomly generated data to a financial price series that first gets added to the IGChartView instance, next the financial indicator is added to the IGChartView instance as a series, and then the IGChartView is added as a subview of the current UIView.


This code example requires the inclusion of the IGChartView framework, detail about how to add this framework can be found in the Adding the Chart Framework File topic.


In Objective-C:

    NSMutableArray *open = [[NSMutableArray alloc] init];
    for (int i = 0; i < 25; i++) {
        [open addObject:[[NSNumber alloc] initWithDouble:(arc4random() % 100)]];
    NSMutableArray *high = [[NSMutableArray alloc] init];
    for (int i = 0; i < 25; i++) {
        [high addObject:[[NSNumber alloc] initWithDouble:(arc4random() % 100 + 30)]];
    NSMutableArray *low = [[NSMutableArray alloc] init];
    for (int i = 0; i < 25; i++) {
        [low addObject:[[NSNumber alloc] initWithDouble:(arc4random() % 100)]];
    NSMutableArray *close = [[NSMutableArray alloc] init];
    for (int i = 0; i < 25; i++) {
        [close addObject:[[NSNumber alloc] initWithDouble:(arc4random() % 100 + 10)]];
    IGOHLCSeriesDataSourceHelper *source = [[IGOHLCSeriesDataSourceHelper alloc] init];
    source.openValues = open;
    source.highValues = high;
    source.lowValues = low;
    source.closeValues = close;
    IGChartView *infraChart = [[IGChartView alloc] initWithFrame:self.view.frame];
    IGCategoryXAxis *xAxis = [[IGCategoryXAxis alloc] initWithKey:@"xAxis"];
    IGNumericYAxis *yAxis = [[IGNumericYAxis alloc] initWithKey:@"yAxis"];
    [infraChart addAxis:xAxis];
    [infraChart addAxis:yAxis];
    IGFinancialPriceSeries *financialPriceSeries = [[IGFinancialPriceSeries alloc] initWithKey:@"financialPriceSeries"];
    financialPriceSeries.xAxis = xAxis;
    financialPriceSeries.yAxis = yAxis;
    financialPriceSeries.dataSource = source;
    financialPriceSeries.displayType = IGPriceDisplayTypeOHLC;
    IGAverageTrueRangeIndicator *financialIndicator = [[IGAverageTrueRangeIndicator alloc] initWithKey:@"financialIndicator"];
    financialIndicator.xAxis = xAxis;
    financialIndicator.yAxis = yAxis;
    financialIndicator.dataSource = source;
    financialIndicator.thickness = 3.0f;
    financialIndicator.trendLineThickness = 3.0f;
    financialIndicator.trendLineType = IGTrendLineTypeModifiedAverage;
    financialIndicator.trendLinePeriod = 5;
    [infraChart addSeries:financialPriceSeries];
    [infraChart addSeries:financialIndicator];
    [self.view addSubview:infraChart];

In C#:

Random r = new Random();
   List<NSObject> open = new List<NSObject>();
   List<NSObject> high = new List<NSObject>();
   List<NSObject> low = new List<NSObject>();
   List<NSObject> volumes = new List<NSObject>();
List<NSObject> close = new List<NSObject>();
   for(int i = 0;i <25; i++)
    open.Add(new NSNumber(r.Next() % 100));
    high.Add(new NSNumber(r.Next() % 100 + 30));
    low.Add(new NSNumber(r.Next() % 100));
    close.Add(new NSNumber(r.Next() % 100 + 10));
volumes.Add(new NSNumber(r.Next() % 1000000 + 100000));

   IGOHLCSeriesDataSourceHelper source = new IGOHLCSeriesDataSourceHelper();
   source.OpenValues = open.ToArray();
   source.HighValues = high.ToArray();
   source.LowValues = low.ToArray();
   source.CloseValues = close.ToArray();

   source.VolumeValues= volumes.ToArray();

   IGChartView chart = new IGChartView(this.View.Frame);
   chart.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;

   IGCategoryXAxis xAxis = new IGCategoryXAxis("xAxis");
   IGNumericYAxis yAxis = new IGNumericYAxis("yAxis");

   IGFinancialPriceSeries series = new IGFinancialPriceSeries("series");
   series.XAxis = xAxis;
   series.YAxis = yAxis;
   series.DataSource = source;
   series.DisplayType = IGPriceDisplayType.IGPriceDisplayTypeOHLC;



IGAverageTrueRangeIndicator indicator = new IGAverageTrueRangeIndicator ("indicator");
   indicator.XAxis = xAxis;
   indicator.YAxis = yAxis;
   indicator.DataSource = source;
   indicator.TrendLineType = IGTrendLineType.IGTrendLineTypeModifiedAverage;
   indicator.TrendLinePeriod = 5;

Related Content


The following topics provide additional information related to this topic.



This is a group of topics explaining the various types of chart series, supported by the IGChartView control, that are classified as financial indicators.