OPEN-SOURCE SCRIPT
ATR SL/TP Plotter

ATR SL/TP Plotter is a visual risk-management overlay that turns a single ATR reading and a user-defined risk percentage into a complete trade plan: one entry line, one Stop Loss, three scalable Take Profit targets, a shaded reward-versus-risk diagram, and the exact position size that keeps loss exposure equal to the chosen percentage of account balance. Every level is recomputed each bar from volatility rather than from a fixed pip distance, so the plan adapts to regime changes automatically.
Why This Combination
This indicator ties four elements that are commonly handled by separate tools into a single overlay:
Keeping these four pieces in one script ensures that the SL distance used to draw the stop and the SL distance used to size the position are always the same value.
What It Does
How It Works
Direction
In Auto mode, direction is Long when EMA(20) is greater than EMA(50) evaluated on close[1] (the previously closed bar), and Short otherwise. Using the closed bar avoids the flicker that comes from evaluating EMAs on a still-forming bar. The Long / Short inputs bypass the EMA state entirely for discretionary setups.
Levels
ATR is Pine's built-in ta.atr(period). For a Long trade the SL sits ATR × SL-multiplier below the current close, and TP1/TP2/TP3 sit ATR × their multipliers above. For a Short trade the signs are reversed. Because ATR itself is recomputed bar-by-bar, all levels move with current volatility; a quiet range produces tight levels and an expanding range widens them automatically.
Risk:Reward box
On the last bar the script draws four filled boxes anchored at the current bar_index: one from entry down to SL (red, risk), one from entry to TP1 (solid green, primary reward), one from TP1 to TP2 (lighter green), and one from TP2 to TP3 (lightest green). The R:R label shows (TP1 distance) / (SL distance) — i.e. the conservative reward ratio based on the first target.
Position size
Risk amount = balance × risk %. Position size = risk amount / SL distance. The number is reported in the same unit as the price series, so on a 5-digit FX chart it reads as price units per one unit of risk currency; on a stock chart it reads as share count that would lose exactly the risk amount if the stop is hit. The calculation intentionally does not attempt to convert across account currencies — that depends on the user's broker and is better handled externally.
Non-repainting behaviour
Direction comes from close[1] so it does not flip intrabar. The SL/TP levels themselves do update with the current close, which is the correct behaviour for a live risk-management overlay — freezing them to a past close would hide real changes in the volatility environment.
How To Use
Settings
Alerts
Limitations
Disclaimer
This is a risk-management visualisation tool. It does not generate trade signals, does not place orders, and does not guarantee any outcome. Users remain fully responsible for entry decisions, broker execution, and the accuracy of account-balance and risk inputs.
Why This Combination
This indicator ties four elements that are commonly handled by separate tools into a single overlay:
- An ATR-driven stop that scales with current volatility, not with a fixed pip input.
- Three independent Take Profit targets (TP1 / TP2 / TP3) so a partial-exit ladder can be modelled directly on the chart.
- A visibly-shaded Risk:Reward box — red for the risk leg (entry to SL), green for the reward leg (entry to TP1, with lighter shading out to TP3) — so the geometric R:R is legible before any number is read.
- A position-size calculator that consumes the same ATR-based SL distance together with account balance and risk percentage, so the size shown is internally consistent with the drawn stop.
Keeping these four pieces in one script ensures that the SL distance used to draw the stop and the SL distance used to size the position are always the same value.
What It Does
- Detects trade direction automatically via an EMA(20) / EMA(50) state on the previous bar, or accepts a manual Long / Short override.
- Computes SL = entry ± ATR × SL-multiplier, and TP1 / TP2 / TP3 = entry ± ATR × their respective multipliers.
- Draws entry, SL, and three TP lines with labels; optionally repeats the drawing on the last N bars for history.
- Draws a filled Risk:Reward box on the last bar with distinct shading for the SL zone and each TP zone.
- Computes position size as (account balance × risk %) / SL distance and displays it on a compact dashboard together with entry price, SL price, ATR value, R:R ratio (TP1 over SL), TP1/TP2/TP3 prices, and the risk amount in account currency.
- Fires alerts when the EMA-based auto direction flips to Long or to Short.
How It Works
Direction
In Auto mode, direction is Long when EMA(20) is greater than EMA(50) evaluated on close[1] (the previously closed bar), and Short otherwise. Using the closed bar avoids the flicker that comes from evaluating EMAs on a still-forming bar. The Long / Short inputs bypass the EMA state entirely for discretionary setups.
Levels
ATR is Pine's built-in ta.atr(period). For a Long trade the SL sits ATR × SL-multiplier below the current close, and TP1/TP2/TP3 sit ATR × their multipliers above. For a Short trade the signs are reversed. Because ATR itself is recomputed bar-by-bar, all levels move with current volatility; a quiet range produces tight levels and an expanding range widens them automatically.
Risk:Reward box
On the last bar the script draws four filled boxes anchored at the current bar_index: one from entry down to SL (red, risk), one from entry to TP1 (solid green, primary reward), one from TP1 to TP2 (lighter green), and one from TP2 to TP3 (lightest green). The R:R label shows (TP1 distance) / (SL distance) — i.e. the conservative reward ratio based on the first target.
Position size
Risk amount = balance × risk %. Position size = risk amount / SL distance. The number is reported in the same unit as the price series, so on a 5-digit FX chart it reads as price units per one unit of risk currency; on a stock chart it reads as share count that would lose exactly the risk amount if the stop is hit. The calculation intentionally does not attempt to convert across account currencies — that depends on the user's broker and is better handled externally.
Non-repainting behaviour
Direction comes from close[1] so it does not flip intrabar. The SL/TP levels themselves do update with the current close, which is the correct behaviour for a live risk-management overlay — freezing them to a past close would hide real changes in the volatility environment.
How To Use
- Add the indicator to the chart you want to trade. The default ATR(14) with SL ×1.5 and TP ×1 / ×2 / ×3 is a neutral starting point for most liquid markets.
- Read the Risk:Reward box first. If the green reward zone to TP1 is visibly smaller than the red risk zone, the trade's geometric R:R is below 1:1 — usually a reason to wait or widen the target.
- Tune the multipliers to your style. Tighter entries (for range trades or scalps) often use SL ×1.0 with TP ×1 / ×1.5 / ×2. Longer swings typically widen SL to ×2 and push TP3 out to ×4 or ×5.
- Enter the same balance and risk percentage you actually use. The dashboard's Size field is only meaningful when those two inputs reflect your real account.
- Override direction manually when you have a discretionary thesis that conflicts with the EMA reading — this is what the Long / Short modes are for.
- Combine with your own entry trigger. This tool does not decide when to enter; it only describes what the trade plan looks like once you have decided.
Settings
- Direction — Auto / Long / Short.
- Show on — Last Bar Only, or Last N Bars (1–20).
- ATR Period — Default 14.
- SL Multiplier — Default 1.5, range 0.5–5.0.
- TP1 / TP2 / TP3 Multiplier — Defaults 1.0 / 2.0 / 3.0, each 0.1–10.0.
- Account Balance — Default 10,000 in account currency.
- Risk % — Default 1.0%, range 0.1–10.0.
- Table Position / Size — Nine positions, three sizes.
- Show R:R Box / Show TP/SL Lines — Independent toggles.
Alerts
- Direction: Long — fires when auto-detected direction flips from Short to Long.
- Direction: Short — fires when auto-detected direction flips from Long to Short.
Limitations
- This is a visualisation and sizing tool. It does not forecast price direction, does not place orders, and does not guarantee any outcome.
- The SL and TP levels are ATR-based geometric plots of where a stop or target would sit — they are not executed orders. Actual fills depend on broker spread, slippage, and execution, none of which this script models.
- The auto-direction flag is an EMA(20)/EMA(50) state on the previous bar. It is a simple bias indicator, not a trade entry signal, and can lag sharply after fast reversals; use the Long/Short manual override when the EMA reading disagrees with your own analysis.
- SL/TP multipliers are fixed scalars on ATR — they do not adapt per regime. In gap-prone or news-driven markets the same ATR × SL multiplier can be too tight (stopped out on noise) or too wide (unfavourable R:R). Tune the multipliers to the instrument and session.
- Position size is computed as risk amount divided by SL distance in price units. It does not convert across account currencies, does not include commission or swap, and assumes the SL fills exactly at the plotted price.
- ATR needs at least ATR Period bars of history to produce a stable reading; on newly listed symbols or very short histories, early bars will show degraded or N/A ATR values.
Disclaimer
This is a risk-management visualisation tool. It does not generate trade signals, does not place orders, and does not guarantee any outcome. Users remain fully responsible for entry decisions, broker execution, and the accuracy of account-balance and risk inputs.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.