Overview The Average True Range (ATR) is a widely-used volatility indicator in technical analysis. It quantifies market volatility by measuring the average price range over a specified period. ATR does not indicate the direction of the trend but helps identify periods of high or low volatility.
Syntax
const period = 12; // The lookback period for the ATR calculation
const atr = new I.ATR([period]);
## Parameters
1. **`period`** (Integer):
- The number of periods used to calculate the average true range.
- For example, a `period` of 12 calculates the average of the true range for the last 12 data points.
## Returns
The `ATR` object provides a series of ATR values, where each value represents the average true range for the corresponding data point. The initial values may be `undefined` if the data points are insufficient to compute the ATR for the specified `period`.
## ATR Calculation
1. **True Range (TR)**:
The TR for each period is the maximum of:
- Current high minus current low.
- Absolute difference between the current high and the previous close.
- Absolute difference between the current low and the previous close.
2. **Average True Range (ATR)**:
The ATR is calculated as the average of the True Range over the specified `period`.
## Example Usage
### Basic Implementation
```jsx
const period = 14; // Calculate ATR over 14 periods
const atr = new I.ATR([period]);
console.log(atr); // Outputs an array containing ATR values
ATR can help set stop-loss levels that adapt to market volatility:
const iv = HFS.indicatorValues(state); // Get the latest ATR value
const { price } = update;
// Example: Stop-loss placed 2 ATRs below the current price
const stopLoss = price - 2 * iv.atr;
console.log(`Stop-loss level: ${stopLoss}`);