OPEN-SOURCE SCRIPT
Dynamic Stop Loss Optimizer [BackQuant]

Dynamic Stop Loss Optimizer [BackQuant]
Overview
Stop placement decides expectancy. This tool gives you three professional-grade, adaptive stop engines, ATR, Volatility, and Hybrid. So your exits scale with current conditions instead of guessing fixed ticks. It trails intelligently, redraws as the market evolves, and annotates the chart with clean labels/lines and a compact stats table. Pick the engine that fits the trade, or switch on the fly.
What it does
Why it matters
The three methods (choose your engine)
1) ATR Based “Structure-aware” distance
This classic approach keys off Average True Range to set a stop just beyond typical bar-to-bar excursion. It adapts smoothly to changing ranges and respects swing structure.
Use when: you want a steady, intuitive buffer that tracks trend legs without hugging price.
See it in action:
2) Volatility Based “Behavior-aware” distance
This engine derives stop distance from current return volatility (annualized, then scaled back down to the session). It reacts to regime shifts quickly and normalizes risk across symbols with very different prices.
Use when: you want the stop to breathe with realized volatility and respond faster to heat-ups/cool-downs.
See it in action:
3) Hybrid “Best of both worlds”
The Hybrid blends the ATR and Volatility distances into one consensus level, then trails it intelligently. You get the structural common sense of ATR and the regime sensitivity of Vol.
Use when: you want robust, all-weather behavior without micromanaging inputs.
See it in action:
How it trails
Reading the chart
Quick workflow
Inputs you’ll actually touch
Calculation Settings
Stop Loss Method
Position Type
Visual Settings
Coloring
Practical patterns to watch
Alerts
Why this feels “set-and-serious”
You get a single look that answers three questions in real time: “Where’s my line in the sand?”, “How much heat am I taking right now?”, and “Is this distance appropriate for current conditions?” With ATR, Vol, and Hybrid in one tool, you can run the exact same playbook across symbols and regimes while keeping your chart clean and your risk explicit.
Overview
Stop placement decides expectancy. This tool gives you three professional-grade, adaptive stop engines, ATR, Volatility, and Hybrid. So your exits scale with current conditions instead of guessing fixed ticks. It trails intelligently, redraws as the market evolves, and annotates the chart with clean labels/lines and a compact stats table. Pick the engine that fits the trade, or switch on the fly.
What it does
- Calculates three adaptive stops in real time (ATR-based, Volatility-based, and Hybrid) and keeps them trailed as price makes progress.
- Shows exactly where your risk lives with on-chart levels, color-coded markers (long/short), and precise “Risk %” labels at the current bar.
- Surfaces context you actually use - current ATR, daily volatility, selected method, and the live stop level—in a tidy, movable table.
- Fires alerts on stop hits so you can automate exits or journal outcomes without staring at the screen.
Why it matters
- Adaptive risk control: Stops expand in fast tape and tighten in quiet tape. You’re not punished for volatility; you’re aligned with it.
- Consistency across assets: The same playbook works whether you’re trading indexes, FX, crypto, or equities, because the engine normalizes to each symbol’s behavior.
- Cleaner decision-making: One chart shows your entry idea and its invalidation in the same breath. If price trespasses, you know it instantly.
The three methods (choose your engine)
1) ATR Based “Structure-aware” distance
This classic approach keys off Average True Range to set a stop just beyond typical bar-to-bar excursion. It adapts smoothly to changing ranges and respects swing structure.
Use when: you want a steady, intuitive buffer that tracks trend legs without hugging price.
See it in action:
2) Volatility Based “Behavior-aware” distance
This engine derives stop distance from current return volatility (annualized, then scaled back down to the session). It reacts to regime shifts quickly and normalizes risk across symbols with very different prices.
Use when: you want the stop to breathe with realized volatility and respond faster to heat-ups/cool-downs.
See it in action:
3) Hybrid “Best of both worlds”
The Hybrid blends the ATR and Volatility distances into one consensus level, then trails it intelligently. You get the structural common sense of ATR and the regime sensitivity of Vol.
Use when: you want robust, all-weather behavior without micromanaging inputs.
See it in action:
How it trails
- Longs: The stop ratchets up with favorable movement and holds its ground on shallow pullbacks. If price closes back into the risk zone, the level refreshes to the newest valid distance.
- Shorts: Mirror logic ratchets down with trend, resists noise, and refreshes if price reclaims the zone.
- Hybrid trailing: Uses the blended distance and the same “no give-backs” principle to keep gains protected as structure builds.
Reading the chart
- Markers: Circles = ATR stops, Crosses = Vol stops, Diamonds = Hybrid. Colors indicate long (red level under price) vs short (green level above price).
- Lines: The latest active stop is extended with a dashed line so you can see it at a glance.
- Labels: “Long SL / Short SL” shows the exact price and current risk % from the last close no math required.
- Table: ATR value, Daily Vol %, your chosen Method, the Current SL, and Risk %—all in one compact block that you can pin top-left/right/center.
Quick workflow
- Define the idea: Long or Short, and which engine fits the tape (ATR, Vol, or Hybrid).
- Place and trail: Let the optimizer print the level; trail automatically as the move develops.
- Manage outcomes: If the line is tagged, you’re out clean. If it holds, you’ve contained heat while giving the trade room to work.
Inputs you’ll actually touch
Calculation Settings
- ATR Length / Multiplier: Controls the “structural” cushion.
- Volatility Length / Multiplier: Controls the “behavioral” cushion.
- Trading Days: 252 or 365 to keep the volatility math aligned with the asset’s trading calendar.
Stop Loss Method
- ATR Based | Volatility Based | Hybrid: Switch engines instantly to fit the trade.
Position Type
- Long | Short | Both: Show only what you need for the current strategy.
Visual Settings
- Show ATR / Vol / Hybrid Stops: Toggle families on/off.
- Show Labels: Print price + Risk % at the live stop.
- Table Position: Park the metrics where you like.
Coloring
- Long/Short/Hybrid colors: Set a palette that matches your theme and stands out on your background.
Practical patterns to watch
- Trend-pullback continuation: The stop ratchets behind higher lows (long) or lower highs (short). If price tests the level and rejects, that’s your risk-defined continuation cue.
- Break-and-run: After a clean break, the Hybrid will usually sit slightly wider than pure Vol, use it to avoid getting shaken on the first retest.
- Range compression: When the ATR and Vol distances converge, the table will show small Risk %. That’s your green light to size up with the same dollar risk, or keep it conservative if you expect expansion.
Alerts
- Long Stop Loss Hit: Notifies when price crosses below the live long stop.
- Short Stop Loss Hit: Notifies when price crosses above the live short stop.
Why this feels “set-and-serious”
You get a single look that answers three questions in real time: “Where’s my line in the sand?”, “How much heat am I taking right now?”, and “Is this distance appropriate for current conditions?” With ATR, Vol, and Hybrid in one tool, you can run the exact same playbook across symbols and regimes while keeping your chart clean and your risk explicit.
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
Check out whop.com/signals-suite for Access to Invite Only Scripts!
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
Check out whop.com/signals-suite for Access to Invite Only Scripts!
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。