Skip to content
GetProfitable
Search
Risk and sizing

ATR Risk Guide

A small panel showing current ATR, the stop distance a chosen multiple implies, and how many units that buys for a fixed dollar risk, so sizing is read off the chart rather than guessed.

indicator
//@version=6
indicator("ATR Risk Guide", "Risk", overlay = true)

atrLen = input.int(14, "ATR length", minval = 1, group = "Settings")
mult = input.float(1.5, "Stop distance in ATR", minval = 0.1, step = 0.1, group = "Settings")
riskDollars = input.float(100, "Risk per trade", minval = 1, step = 1, group = "Settings")
textCol = input.color(#787B86, "Text", group = "Style")

atr = ta.atr(atrLen)
stopDistance = atr * mult
units = stopDistance > 0 ? math.floor(riskDollars / stopDistance) : 0

var table panel = table.new(position.top_right, 2, 3, border_width = 1)

if barstate.islast
    table.cell(panel, 0, 0, "ATR", text_color = textCol, text_size = size.small)
    table.cell(panel, 1, 0, str.tostring(atr, format.mintick), text_color = textCol, text_size = size.small)
    table.cell(panel, 0, 1, "Stop distance", text_color = textCol, text_size = size.small)
    table.cell(panel, 1, 1, str.tostring(stopDistance, format.mintick), text_color = textCol, text_size = size.small)
    table.cell(panel, 0, 2, "Units", text_color = textCol, text_size = size.small)
    table.cell(panel, 1, 2, str.tostring(units), text_color = textCol, text_size = size.small)
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.

What it will not do

  • Units are rounded down and ignore fees, slippage and contract multipliers. Check the number against your broker before trading it.
  • A volatility-based stop is not automatically a sensible stop. It has no idea where the levels on your chart are.

Written from this description

Show a table in the corner with the current ATR, a stop distance of ATR times a multiplier, and the position size that risks a fixed dollar amount at that stop distance.

Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.