Volatility indicator
ATR Calculator
Compute the current Average True Range for one bar from its high, low, the previous close, and the previous ATR. What ATR represents, the typical size of a bar's movement, is the useful part.
What the ATR is
Average True Range, another of J. Welles Wilder's 1978 indicators, measures how much an instrument typically moves per bar. It starts with the True Range, which captures the full extent of a bar's movement including any gap from the previous close.
True Range is the largest of three distances: the current high minus the current low, the absolute difference between the current high and the previous close, and the absolute difference between the current low and the previous close. Using the previous close ensures overnight gaps are counted, not just the visible bar. ATR is then Wilder's smoothed average of True Range over the chosen period, by default 14, so each new value blends the prior average with the latest True Range rather than dropping an old bar abruptly.
Why the ATR is used
ATR is a pure volatility gauge: it says nothing about direction, only about the size of movement. It is widely used to size stops and targets in a way that adapts to current conditions, to compare volatility between instruments, and to filter for quiet or active markets.
Because it is expressed in the same units as price, ATR is often turned into a multiple, such as a stop placed a set number of ATRs away from a level. How you apply it is entirely your own decision.
What are TradingView and Pine Script?
TradingView is one of the most widely used charting and market-analysis platforms, where traders and analysts study price movement across stocks, crypto, forex, and futures on interactive charts. Pine Script is TradingView's own lightweight programming language, created so anyone can build custom tools that run directly on those charts.
People use Pine Script to build four main kinds of tools. Indicators calculate and plot values on the chart, exactly like the calculation above, but recomputed automatically on every bar. Strategies add explicit entry and exit rules and can be backtested against historical data in TradingView's Strategy Tester to see how they would have behaved. Screeners scan many symbols at once for conditions you define. Alerts notify you the moment a condition you specified occurs, so you do not have to watch the screen.
The value is precision and automation. Instead of eyeballing a chart, you describe exactly what you want measured, visualized, or notified about, and TradingView runs it consistently across any market and timeframe. That is why traders, analysts, and developers write Pine Script: it turns a manual charting idea into a repeatable tool. These tools are for tracking, visualizing, and testing market ideas; they do not tell you what to trade, and that decision always remains yours.
Writing that code by hand means learning Pine Script's syntax, its type system, and the exact names of hundreds of built-in functions. It is a real programming language, and small mistakes stop a script from compiling in the Pine Editor.
Turn this into Pine Script
You calculated one ATR reading here. In a live indicator you would want ATR recalculated on every bar so it always reflects current volatility. Pine Script gives you the value with a single call, ta.atr(14), but building a trailing stop, position sizing, or a volatility filter around it is the involved part.
//@version=6
indicator("ATR", overlay=false)
length = input.int(14, "ATR Length")
atrValue = ta.atr(length)
plot(atrValue, "ATR", color=color.red)PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready v5 or v6 code. Because it is specialized on the Pine Script language and its exact function signatures, it tends to produce code that compiles far more reliably than general-purpose models like ChatGPT, which often invent functions that do not exist in Pine Script.
PineScripter is an AI developer tool that helps you write Pine Script code. It is not a financial advisor and will never offer financial, investment, or trading advice. Everything on this page, including the calculator and the explanations, is provided purely for educational and informational purposes. Any decision about how to interpret an indicator or trade a market is entirely your own. See our full disclaimer for more.