OPEN-SOURCE SCRIPT
Mis à jour Futures ATR Risk & Position Sizer

ATR Risk & Position Sizer
What it does
This tool answers one question before every trade: "Given how much I'm willing to lose and how volatile this market is right now, how many contracts can I actually take?"
Instead of using a fixed stop distance, the stop is derived from the Average True Range (ATR) of the instrument, so position size automatically shrinks when volatility rises and grows when it falls — the dollar risk stays constant, the contract count adapts.
The asset is auto-detected from the chart you're viewing. You only choose whether you're trading the Mini or Micro version of it.
How the calculation works
Auto-detection
The script reads the chart's root symbol (works with both continuous contracts like ES1! and dated contracts like ESZ2025) and matches it — along with its known Micro ticker — against a built-in list of instruments. If the symbol isn't recognized, the table is replaced with a clear red "Unsupported Asset" warning instead of showing incorrect numbers.
If the asset is recognized but the size you selected (Mini/Micro) doesn't actually exist for that instrument (e.g. there's no Micro Platinum), you'll get an orange warning instead of silently wrong output.
Supported instruments and their specs:
Asset | Root / Micro ticker(s) | Tick Size | Mini $/pt | Micro $/pt
"N/A" means that instrument currently has no Micro-sized version on the exchange — the script will flag this rather than show a value.
Inputs
Reading the table
Notes & disclaimer
What it does
This tool answers one question before every trade: "Given how much I'm willing to lose and how volatile this market is right now, how many contracts can I actually take?"
Instead of using a fixed stop distance, the stop is derived from the Average True Range (ATR) of the instrument, so position size automatically shrinks when volatility rises and grows when it falls — the dollar risk stays constant, the contract count adapts.
The asset is auto-detected from the chart you're viewing. You only choose whether you're trading the Mini or Micro version of it.
How the calculation works
- Stop distance = ATR(length) × Multiplier
- ATR length defaults to 14 (configurable).
- The multiplier (default 1.5) controls how wide the stop is relative to current volatility — this is what makes the risk "dynamic": as ATR expands or contracts, so does the stop, and so does the resulting position size. - Tick rounding — a stop can only be placed at a valid price increment (tick), so the raw ATR-based distance is rounded down to the nearest whole tick for the detected instrument before anything else is calculated. For example, on ES (tick = 0.25), a raw distance of 10.4 points becomes 10.25 points (41 ticks) — never a value that couldn't actually be set as a stop order.
- Risk per contract = Stop Distance (points) × Dollar value per point (for the selected Mini/Micro size).
- Contracts allowed = floor(Max Risk $ ÷ Risk per contract), then optionally rounded down to the nearest even number (see below).
- Max Risk (displayed) is recalculated from the final, rounded contract count — so it reflects your actual exposure, which will always be at or under your configured max risk, never over it.
Auto-detection
The script reads the chart's root symbol (works with both continuous contracts like ES1! and dated contracts like ESZ2025) and matches it — along with its known Micro ticker — against a built-in list of instruments. If the symbol isn't recognized, the table is replaced with a clear red "Unsupported Asset" warning instead of showing incorrect numbers.
If the asset is recognized but the size you selected (Mini/Micro) doesn't actually exist for that instrument (e.g. there's no Micro Platinum), you'll get an orange warning instead of silently wrong output.
Supported instruments and their specs:
Asset | Root / Micro ticker(s) | Tick Size | Mini $/pt | Micro $/pt
- E-mini S&P 500 | ES / MES | 0.25 | $50 | $5
- E-mini Nasdaq 100 | NQ / MNQ | 0.25 | $20 | $2
- E-mini Dow | YM / MYM | 1.0 | $5 | $0.50
- E-mini Russell 2000 | RTY / M2K | 0.10 | $50 | $5
- Gold | GC / MGC (also XAUUSD, GOLD) | 0.10 | $100 | $10
- Silver | SI / SIL (also XAGUSD) | 0.005 | $5,000 | $1,000
- Platinum | PL | 0.10 | $50 | N/A
- Copper | HG / MHG | 0.0005 | $25,000 | $2,500
- Crude Oil | CL / MCL | 0.01 | $1,000 | $100
- Natural Gas | NG / MNG | 0.001 | $10,000 | $1,000
- Heating Oil | HO | 0.0001 | $42,000 | N/A
- RBOB Gasoline | RB | 0.0001 | $42,000 | N/A
- US Dollar Index | DX | 0.005 | $1,000 | N/A
- Euro FX | 6E / M6E | 0.00005 | $125,000 | $12,500
- British Pound | 6B / M6B | 0.0001 | $62,500 | $6,250
- Australian Dollar | 6A / M6A | 0.0001 | $100,000 | $10,000
- 30-Yr T-Bond | ZB | 1/32 (0.03125) | $1,000 | N/A
- 10-Yr T-Note | ZN | 1/64 (0.015625) | $1,000 | N/A
- Wheat | ZW | 0.25 | $50 | N/A
- Soybeans | ZS | 0.25 | $50 | N/A
- Corn | ZC | 0.25 | $50 | N/A
- Cotton | CT | 0.01 | $500 | N/A
- Sugar | SB | 0.01 | $1,120 | N/A
- Coffee | KC | 0.05 | $375 | N/A
- Cocoa | CC | 1.0 | $10 | N/A
"N/A" means that instrument currently has no Micro-sized version on the exchange — the script will flag this rather than show a value.
Inputs
- Max Risk Amount ($) – the dollar amount you're willing to risk on the trade.
- ATR Length – lookback period for ATR (default 14).
- ATR Multiplier – multiplies ATR to set the stop distance (default 1.5).
- Force Even Number of Contracts – when enabled (default), an odd contract count is rounded down to the nearest even number; disable to allow any whole number.
- Contract Type – Mini or Micro. Pick whichever you actually trade; the asset detection is independent of this.
- Table Position / Text Size – purely cosmetic.
Reading the table
- Header – detected asset, contract size, ATR multiplier in use, and your configured risk amount.
- Contracts Allowed – the final, tick-valid, (optionally) even-rounded contract count.
- Stop Loss Distance – the tick-rounded stop distance, shown in both points and whole ticks.
- Max Risk ($) – your actual dollar risk at that contract count — always at or below your configured max risk.
Notes & disclaimer
- Contract specifications (tick size, point value) reflect standard CME/ICE specs at the time of publishing. Exchanges occasionally revise these — please verify against your broker/exchange before relying on this for live sizing.
- This indicator does not generate entry or exit signals. It is a risk-management and position-sizing calculator only.
- Nothing in this script constitutes financial advice. Futures trading involves substantial risk of loss and is not suitable for all investors. Past volatility is not indicative of future volatility.
Notes de version
To improve versatility, the force even number as be changed to a base size configuration,which makes much more sense.
The number of allowed "base size" is now displayed next to the allowed contract number if the base size is superior to 1.
Allowed contract always represent number of base size allowed under the defined risk.
- Removed "Force even number of contract" option.
- Added base size configuration.
- Updated display to represent the new configuration.
Notes de version
Added warning state and risk adjustment for handling volatility spike since ATR is slow to react.The tool now compare the last candle size to a configured threshold and adjust the ATR following this formula: (bar range + current ATR) / 2.
In short: It adjust it to half the distance between current ATR and the largest registered candle exceeding half the threshold for yellow, and the threshold itself for red warning.
There is a configurable bar countdown to downgrade. As long as the condition is exceeded, that counter reset. So you set the amount of cooling time you want after volatility spike to re-introduced full risk.
You can also disable the contract & risk adjustment and keep only the colour warning if you prefer.
Notes de version
Increased default tolerance to 80% to give a better initial feel.Notes de version
Reduced default countdown to 3.Updated chart image.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.