OPEN-SOURCE SCRIPT

Stop Loss with ATR Buffer

71
1. Core Logic
Long Positions: Places a stop-loss below the previous bar's low by a buffer of ATR * bufferMultiplier.
Short Positions: Places a stop-loss above the previous bar's high by the same ATR-based buffer.
2. Key Features
ATR Volatility Adjustment:
Uses the Average True Range (ta.atr()) to adapt stop distances to market volatility. Larger ATR values widen the stop buffer during volatile markets.

User-Defined Buffer:
The bufferMultiplier lets you fine-tune how tightly/loosely stops follow price (e.g., 0.5 uses half the ATR value).

3. Visualization
Dynamic Lines:
Plots two lines on the chart:

Green for long stop levels.
Red for short stop levels.
Lines update on every bar to reflect new price action.
Historical Levels:
Optional trailing lines show only the most recent stop levels (avoysluttering the chart).

4. Use Cases
Trailing Stop-Loss: Track price momentum while maintaining a volatility-based safety margin.
Entry Confirmation: Identify potential reversal zones where price breaks through the ATR-buffered stops.
Risk Management: Size stops proportionally to market volatility, avoiding fixed-price thresholds.
Example Scenario:
If the previous candle’s low is $100, ATR is $2, and bufferMultiplier = 0.5:
Long Stop = 100 - (2 * 0.5) = $99.
Price must drop below $99 to trigger the stop, giving trades breathing room.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.