Category Other  Published on 11/05/2024

AverageTrueRange

An update for this algorithm is currently pending moderation. Please revisit this page shortly to access the algorithm's latest version.
Description

This code is for calculating the Average True Range (ATR) indicator in cAlgo, a platform for algorithmic trading. The ATR measures market volatility by taking into account the range between a security's high and low prices.

Here's a breakdown of what the code does:

  1. It defines a class named AverageTrueRange that inherits from the Indicator class provided by cAlgo.
  2. The Initialize method initializes two IndicatorDataSeries objects: _trueRange and _atr. These will store the true range and ATR values, respectively.
  3. The Calculate method is where the ATR calculation is performed for each index (or bar) of historical data.
  4. Inside the Calculate method, it first checks if there is enough data to calculate ATR (index < AtrPeriod). If not, it returns without performing any calculations.
  5. For the first AtrPeriod bars, it calculates the ATR as the simple average of the true range over those bars.
  6. For subsequent bars, it updates the ATR using a recursive formula: (previous ATR * (AtrPeriod - 1) + current true range) / AtrPeriod.
  7. Finally, it draws the ATR value on the chart for the last bar.



SH
shapor33

Joined on 08.04.2024 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: AverageTrueRange.algo
  • Rating: 0
  • Installs: 289
  • Modified: 11/05/2024 11:26
Comments
Log in to add a comment.
No comments found.