## Function Prototype

```
/* Average True Range */
/* Type: indicator */
/* Input arrays: 3 Options: 1 Output arrays: 1 */
/* Inputs: high, low, close */
/* Options: period */
/* Outputs: atr */
int ti_atr_start(TI_REAL const *options);
int ti_atr(int size,
TI_REAL const *const *inputs,
TI_REAL const *options,
TI_REAL *const *outputs);
```

## Description

This documentation is still a work in progress. It has omissions, and it probably has errors too. If you see any issues, or have any general feedback, please get in touch.

Average True Range is a measure of volatility. It represents roughly how much you can expect a security to change in price on any given day. It is often used in position sizing formulas.

Average true range is calculated by applying Wilders Smoothing to True Range.

True range for each day is the greatest of:

- Day's high minus day's low
- The absolute value of the day's high minus the previous day's close
- The absolute value of the day's low minus the previous day's close

$$tr_{t} = maximum(high_{t} - low_{t}, |high_{t} - close_{t-1}|, |low_{t} - close_{t-1}|)$$

True range is then smoothed using Wilders Smoothing which yields the average true range.

$$atr_{t} = tr_{t} \cdot \frac{1}{n} + atr_{t-1} \cdot \frac{n-1}{n}$$

## See Also

## References

- Kaufman, Perry J. (2013) Trading Systems and Methods
- Wilder, J. Welles (1978) New Concepts in Technical Trading Systems
- Murphy, J. (1999) Technical Analysis of the Financial Markets
- Achelis, S. (2000) Technical Analysis from A to Z, 2nd Edition
- Wikipedia: Average true range

## Example Usage

### Calling From C

```
/* Example usage of Average True Range */
/* Assuming that 'high', 'low', and 'close' are pre-loaded arrays of size 'in_size'. */
TI_REAL *inputs[] = {high, low, close};
TI_REAL options[] = {5}; /* period */
TI_REAL *outputs[1]; /* atr */
/* Determine how large the output size is for our options. */
const int out_size = in_size - ti_atr_start(options);
/* Allocate memory for output. */
outputs[0] = malloc(sizeof(TI_REAL) * out_size); assert(outputs[0] != 0); /* atr */
/* Run the actual calculation. */
const int ret = ti_atr(in_size, inputs, options, outputs);
assert(ret == TI_OKAY);
```

### Calling From Lua (with Tulip Chart bindings)

```
-- Example usage of Average True Range
atr = ti.atr(high, low, close, 5)
```

## Example Calculation

period = 5

date | high | low | close | atr |
---|---|---|---|---|

2005-11-01 | 82.15 | 81.29 | 81.59 | |

2005-11-02 | 81.89 | 80.64 | 81.06 | |

2005-11-03 | 83.03 | 81.31 | 82.87 | |

2005-11-04 | 83.30 | 82.65 | 83.00 | |

2005-11-07 | 83.85 | 83.07 | 83.61 | 1.12 |

2005-11-08 | 83.90 | 83.11 | 83.15 | 1.05 |

2005-11-09 | 83.33 | 82.49 | 82.84 | 1.01 |

2005-11-10 | 84.30 | 82.30 | 83.99 | 1.21 |

2005-11-11 | 84.84 | 84.15 | 84.55 | 1.14 |

2005-11-14 | 85.00 | 84.11 | 84.36 | 1.09 |

2005-11-15 | 85.90 | 84.03 | 85.53 | 1.24 |

2005-11-16 | 86.58 | 85.39 | 86.54 | 1.23 |

2005-11-17 | 86.98 | 85.76 | 86.89 | 1.23 |

2005-11-18 | 88.00 | 87.17 | 87.77 | 1.21 |

2005-11-21 | 87.87 | 87.01 | 87.29 | 1.14 |

## Chart

## Other Indicators

Previous indicator: Vector Arctangent

Next indicator: Average Price

Random indicator: Rate of Change

Copyright © 2016-2023 Tulip Charts LLC. All Rights Reserved.