All free tools

Trading metric

ATR Stop Loss Calculator

Set a stop a multiple of Average True Range away from your entry, then size the position so that distance equals the amount you intended to risk. Both halves matter, because a volatility-based stop only means something if the size was derived from it.

Stop price
176.10
6.30 below entry.
Position size
39
Whole units, rounded down.
DetailValue
Stop distance in price6.30
Stop distance as % of entry3.45%
Amount at risk250.00
Position size (exact)39.6825
Position size (whole units)39
Position value at entry7,238.10
Position value vs account0.29x

Why stops get anchored to ATR

Average True Range measures how much an instrument typically moves in a single bar, including the gaps between bars. A stop placed a fixed number of dollars or a fixed percentage away from entry ignores that, so the same rule that gives a quiet instrument plenty of room will sit inside the normal noise of a volatile one. Anchoring the distance to ATR makes the stop adapt: it widens when the instrument is moving more and tightens when it settles down.

The multiplier is the part you choose, and the tradeoff is direct. A larger multiple places the stop further away, which means normal fluctuation is less likely to reach it, but it also means each unit carries more risk, so a fixed risk budget buys a smaller position. A smaller multiple does the reverse. There is no correct value, and nothing here suggests one; it is a modelling decision that belongs to you.

Read ATR in the same units as your price. If your chart shows ATR as 3.15 on an instrument priced at 182.40, then a 2x stop sits 6.30 away, which is about 3.5% of the entry price. That percentage is worth glancing at, because it tells you whether the volatility-based distance is reasonable for the instrument or whether the multiplier is producing something extreme.

Sizing is the other half

A stop distance on its own does not control anything. What determines how much of the account is exposed is the combination of that distance and the number of units held. The arithmetic is a single division: the amount you are willing to risk, divided by the per-unit distance from entry to stop. Risk 250 on a stop 6.30 away and the position is about 39 units.

Three details around that division cause most of the real-world problems. Fractional results have to be rounded, and rounding down is the safe direction because rounding up increases the risk above what you specified. A rounded result can land on zero, which is not a small position but no position at all, and it needs to be handled explicitly rather than silently. And on early bars, before ATR has enough history to produce a value, the distance is undefined, so dividing by it produces either an error or a nonsensical size.

The last point deserves emphasis because it is the one people skip: the stop you sized against has to be the stop you actually place. If the quantity was derived from a distance of 6.30 but no protective order sits at that level, the calculation describes a risk the position is not enforcing. Our guide to position size in Pine Script works through how those two stay consistent in code.

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 this from one ATR reading at one moment. In Pine Script the same rule runs on every bar: ta.atr() recomputes the range, the stop distance follows it, and the quantity is recalculated from current equity before each entry. That is the difference between a stop you worked out by hand and one that adapts automatically as conditions change.

Two lines in the code above are the ones worth copying carefully. The validStop guard prevents dividing by an ATR that has not warmed up yet, and the strategy.exit() call places the stop at the exact distance the sizing used. Skipping either produces a strategy that either errors on early bars or silently takes a different risk than intended. You can cross-check the ATR figure itself with our ATR calculator.

Pine Script v6
//@version=6
strategy("ATR stop with matched sizing", overlay = true)

atrLength  = input.int(14,    "ATR length",            minval = 1)
atrMult    = input.float(2.0, "Stop distance (x ATR)", minval = 0.1)
riskPercent = input.float(1.0, "Risk % of equity",     minval = 0.1, maxval = 100)

atrValue     = ta.atr(atrLength)
stopDistance = atrValue * atrMult
riskAmount   = strategy.equity * riskPercent / 100

// ATR is na until it has warmed up, so guard the division before using it.
validStop = not na(stopDistance) and stopDistance > 0
qty       = validStop ? math.floor(riskAmount / stopDistance) : 0

longSignal = ta.crossover(ta.sma(close, 10), ta.sma(close, 30))

if longSignal and qty > 0
    stopPrice = close - stopDistance
    strategy.entry("Long", strategy.long, qty = qty)
    // The stop you sized against must be the stop you actually place.
    strategy.exit("Long exit", from_entry = "Long", stop = stopPrice)

plot(ta.atr(atrLength), "ATR")

PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready 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.

Related free calculators

From the blog

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.