//@version=5 // Baroq ATR Stop and Position Size. Open source under the Mozilla Public License 2.0, (c) 2026 Baroq Tech. // Draws where a stop a set number of ATRs away would sit, and works out the position size that loses only the risk you // chose if that stop is hit. Education and planning only: it never trades and it is not advice. indicator("Baroq ATR Stop and Position Size", shorttitle="Baroq Stop & Size", overlay=true) atrLen = input.int(14, "ATR length", minval=1) mult = input.float(1.5, "Stop distance, in ATRs", minval=0.1, step=0.1) account = input.float(10000, "Account size", minval=1, group="Position size") riskPct = input.float(1.0, "Risk per trade, %", minval=0.01, maxval=100, step=0.05, group="Position size") perLot = input.float(100, "Units in one lot", minval=0.0001, group="Position size", tooltip="Gold (XAUUSD) at most brokers: 100 ounces. Check your broker's contract size.") a = ta.atr(atrLen) dist = mult * a money = account * riskPct / 100 lots = dist > 0 ? money / (dist * perLot) : na plot(close - dist, "Stop for a buy", color=color.new(#e5534b, 15), linewidth=1) plot(close + dist, "Stop for a sell", color=color.new(#4fb08a, 15), linewidth=1) var table t = table.new(position.top_right, 2, 4, bgcolor=color.new(#0d0d0f, 10), border_color=color.new(#e8c36a, 60), border_width=1) if barstate.islast table.cell(t, 0, 0, "Stop distance", text_color=color.silver, text_size=size.small) table.cell(t, 1, 0, str.tostring(dist, format.mintick), text_color=color.white, text_size=size.small) table.cell(t, 0, 1, "Money at risk", text_color=color.silver, text_size=size.small) table.cell(t, 1, 1, str.tostring(money, "#,##0.00"), text_color=color.white, text_size=size.small) table.cell(t, 0, 2, "Size, lots", text_color=color.silver, text_size=size.small) table.cell(t, 1, 2, str.tostring(lots, "#,##0.00"), text_color=#e8c36a, text_size=size.small) table.cell(t, 0, 3, "Price in the account's currency; costs not included", text_color=color.gray, text_size=size.tiny) table.merge_cells(t, 0, 3, 1, 3)