OPEN-SOURCE SCRIPT

ATR Trailing Stop with ATR Targets [v6]

118
What the Indicator Does
This custom TradingView indicator is designed for active traders who want to automate and visualize their trailing stop management and target setting, using true market volatility. It combines the Average True Range (ATR) with dynamic market structure logic to:

Trail a stop-loss behind major swings in real time, using 2×ATR (adjustable) from the highest high in uptrends or the lowest low in downtrends.

Flip trading bias between bullish and bearish when the stop is breached.

Identify and plot three profit targets (at 1, 2, and 3 ATR from the breakout/flip point) after every stop-flip, helping traders scale out or set take-profits objectively.

Maintain a visible presence on your chart every bar to avoid indicator errors, with color and labeling for clear distinction between long/short phases.

How the Indicator Works
1. ATR Calculation
ATR Period and Multiplier: You select your preferred ATR length (default is 14 bars) and a multiplier (default is 2.0).

Volatility Adjustment: ATR measures the average "true" bar range, so the trailing stop and targets adapt to current volatility.

2. Trailing Stop Logic
Uptrend (bullish bias): The indicator tracks the highest high made since the last bearish-to-bullish flip and sets the stop at [highest high] - [ATR × multiplier].

The stop only raises (never lowers) during an uptrend, protecting gains in strong moves.

Downtrend (bearish bias): Tracks the lowest low made since the last bullish-to-bearish flip, with stop at [lowest low] + [ATR × multiplier].

The stop only lowers (never raises) in a downtrend.

Flip Point: If price closes through the trailing stop, the current bias “flips,” and the logic reverses (bullish to bearish or vice versa). At the new close, flip price and bar index are stored for target calculation.

3. ATR Targets after Flip
After each stop flip:

Three targets—based on the new close price—are calculated and plotted:

Long flip (new bull bias): Target1 = close + 1×ATR, Target2 = close + 2×ATR, Target3 = close + 3×ATR.

Short flip (new bear bias): Target1 = close - 1×ATR, Target2 = close - 2×ATR, Target3 = close - 3×ATR.

These targets help with scaling out, partial profit-taking, or setting automated orders.

4. Visual Feedback
Trailing stop line: Green for long bias, red for short bias.

Targets: Distinct color-coded circles at 1, 2, 3 ATR levels from the most recent flip.

Flip Labels: Mark the bar and price where bias flipped (“Long Flip” or “Short Flip”) for quick pattern recognition.

Subtle background shading: Ensures TradingView's requirement for “indicator output every bar.”

How to Use This Indicator
Parameter Setup
ATR Period and Multiplier: Adjust to match the timeframe and volatility of your instrument.

Lower periods/multipliers for short-term/volatile trading.

Higher values for smoother signals or higher timeframes.

Starting Trend: Set to match the expected initial bias if the instrument has strong trend characteristics.

Trading Application
1. Daily Bias Approach
Establish your bias in line with your trading plan (e.g., only trade long if price is above the previous day's high, short below the previous day's low).

Only look for trades in the indicator's current bias direction, as expressed by the stop and background color.

2. Entry
Use the indicator as a real-time confirmation or trailing stop for your entries.

Breakout: Enter when price establishes the current bias, using the trailing stop as your risk level.

Reversal: Wait for a bias flip after an extended move; enter in the direction of the new bias.

VWAP Rebound: Combine with a VWAP bounce—enter only if the indicator bias supports your direction.

3. Exits/Targets
Trailing stop management: Move your stop according to the plotted line; exit if your stop is hit.

Profit-taking: Scale out or take profits as price approaches each ATR-based target.

Use the dynamic labeling to identify reversal flips and reset your plan if stopped or the bias changes.

4. Market Context
Filter and frame setups by watching correlated indicators (DXY, VIX, AUDJPY, put/call ratio) and upcoming news; trade only in the daily bias direction for best consistency.

5. Practical Tips
Combine this indicator with your custom watchlist and alert settings to get notified on flips or targets.

Review the last label ("Long Flip"/"Short Flip") and targets to plan partial exits.

Remember: ATR adapts to volatility, so the stop and targets stay proportionate even when price action shifts.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.