Pine Script Risk-Reward Ratio Exits
Sets the stop in ticks and lets the take-profit auto-derive from a target risk:reward multiple — no manual math per trade.
Pine Script
//@version=6
strategy("Target Filled - Risk-Reward Exits Example", overlay=true, calc_on_every_tick=false)
// --- Inputs ---------------------------------------------------
stopTicks = input.int(30, "Stop Distance (ticks)", minval=1)
rewardMult = input.float(2.0, "Reward Multiple (R)", minval=0.5, step=0.5,
tooltip="2.0 = take-profit sits at twice the stop distance (2:1).")
// --- Auto-derived target -------------------------------------------
targetTicks = math.round(stopTicks * rewardMult)
// --- Sample signal — replace with your own entry logic ---------
fastMA = ta.ema(close, 9)
slowMA = ta.ema(close, 21)
if ta.crossover(fastMA, slowMA)
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long", profit=targetTicks, loss=stopTicks)
if ta.crossunder(fastMA, slowMA)
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short", profit=targetTicks, loss=stopTicks) Settings
| Input | Default | Purpose |
|---|---|---|
| stopTicks | 30 | Stop distance in ticks. |
| rewardMult | 2.0 | Target reward multiple — take-profit = stop × this value. |
How to use
- Paste into the Pine Editor and swap the EMA-crossover placeholder for your own entry conditions.
- Change only
rewardMultto test 1.5:1, 2:1, or 3:1 — the target recalculates automatically. - Both legs are defined in ticks from entry, so the ratio holds on any symbol; only the dollar amount changes with tick value.
- Combine with the position size calculator snippet to also fix the dollar risk on every trade.
Frequently Asked Questions
How do I set a 2:1 risk reward in Pine Script?
Set the stop distance in ticks, multiply it by 2 to get the take-profit distance, and hand both to
strategy.exit via loss and profit. A 30-tick stop with profit=60, loss=30 is exactly 2:1 on every trade, regardless of where the entry actually fills.How is take profit calculated from risk reward?
Take-profit distance equals the stop distance times the target multiple: a 30-tick stop at 2:1 targets 60 ticks, at 3:1 it targets 90. Because both legs are defined in ticks from the entry rather than in price, the ratio holds on any symbol — only the dollar value of a tick changes what it means in account currency.