OPEN-SOURCE SCRIPT
已更新

ATR Trailing Stops for Hyperliquid Spot + Perps [HYPR-run]

504
DESCRIPTION:
A drop-in ATR trailing exits module. Four architectures that maximize
profit on winning trades using volume weighted volatility instead of fixed levels or
plain ATR. Built modular; the trailing logic is self-contained so you
can drop it into any existing indicator or strategy as a plug-and-play
exits block. Two independent stops (long/short), spot and perps.

DISCOVERING EDGE
ATR trailing exits are popular, everyone uses them, but this indicator doesn't just trail on volatility, it trails on meaningful volatility that very few people measure. In order to gain a persistent, mechanical edge in how winners run and protect capital on the trades that don't work, we explored a more meaningful expression of ATR trailing exits.

VOLUME-WEIGHTED ATR vs PLAIN ATR
Plain ATR treats every candle equally. Volume-weighted ATR will only expand stops when volume validates the volatility, preventing premature exits on noise and letting winners run further on real moves. Over hundreds of trades this single difference can compound in the spirit of letting winners run further, losers stay controlled versus fixed levels or vanilla ATR.

- Four modes (A3.1, A4.0, A4.1, A4.2) cover different trailing
behaviors: ratcheting, chandelier anchor, free-floating, and raw
baseline. All size stop distance from volatility, not fixed levels.
- Modular engine. The trailing logic is self-contained; drop it into
any existing indicator or strategy as a plug-and-play exits block.
- Alerts fire built-in JSON webhook payloads. Paste your webhook URL,
create the alert, execute on the exchange of your choice.

ATR MODES
A3.1: LinReg + plain ATR, no ratchet. The baseline. Linear regression
projects where price is heading, plain ATR sets the distance. Stop moves
freely in both directions. Use as a reference or when you want a raw
trailing stop.

A4.0: LinReg + VWATR + Efficiency Ratio + ratchet (default). The
all-rounder. Volume-weighted ATR discounts low-liquidity candles. The
Efficiency Ratio (Kaufman) measures trend quality: in a clean trend it
widens the stop to let price run; in chop it tightens. Ratchet floor
means the stop only moves in your favor.

A4.1: Chandelier + VWATR + ratchet + first-bar multiplier. Anchored to
the highest high (longs) or lowest low (shorts). First-bar multiplier
sets a tighter initial stop, then the standard multiplier takes over as
the ratchet locks in gains. Use when entering off key levels.

A4.2: LinReg + VWATR, no ratchet. Same as A4.0 but without ratchet
floor or Efficiency Ratio. Stop moves freely with the projection, giving
the trade room through consolidation at the cost of less locked profit.

FEATURES
- Four ATR architectures selectable via dropdown
- Volume-weighted ATR: low-liquidity candles contribute less
- Efficiency Ratio: tightens in chop, widens in trend (A4.0)
- Ratchet floor: stop only moves in your favor (A4.0, A4.1)
- First-bar multiplier for tighter initial protection (A4.1)
- Separate ATR lookbacks for longs and shorts
- Separate multipliers for longs and shorts
- Two-bar confirmation prevents single-wick fakeouts
- Gradient fill between price and stop (intensifies near danger)
- Stop line color shifts with ATR regime (green stable, amber expanding)
- Ratchet circles mark each new locked-in level on the stop line
- Dashboard: mode, stop price, gap %, ER, VWATR %, regime state
- Dark/light theme toggle for any chart background
- Independent long/short alert toggles
- No JSON snippet needed; close payload is built into the script

HOW IT WORKS
Volume-weighted ATR scales each bar's true range by its volume relative
to the lookback average. High-volume bars contribute more; thin candles
contribute less. This prevents low-liquidity spikes from inflating stop
distance. Separate lookbacks for longs (default 14) and shorts (default
26) reflect that crypto drops faster than it climbs.

The Efficiency Ratio measures directional movement versus noise on a 0-1
scale. It scales the ATR multiplier between 0.8x (choppy) and 1.2x
(trending), adapting stop width to market regime. Only active in A4.0.

Two-bar confirmation requires a confirmed close beyond the stop level.
A single wick does not trigger the exit. The cross must hold for at
least one additional bar close.

ALERTS
Close Long fires as SPOT (sell spot position). Close Short fires as
PERPS (close short; spot is long-only). Toggle each independently.
Alert payload is built into the script as JSON; works with any webhook
receiver that accepts market/ticker/position fields.

CREDITS
ATR: J. Welles Wilder (1978)
Efficiency Ratio: Perry Kaufman
版本注释
HOW TO USE
As a standalone indicator: add to chart, select ATR mode, configure multipliers and lookbacks. Toggle Alert Close Longs and Alert Close Shorts independently. The stop lines, gradient fill, and ratchet circles appear on chart. When a close signal fires, a ⌖ marker prints on the bar.

For notifications without webhooks, create a TradingView alert with condition = this indicator, "Any alert() function call", and select push notification, email, or popup.

For webhook execution, paste your endpoint URL in the alert's Webhook URL field, set Open-ended, create. Close Long sends {"market":"SPOT","ticker":"...","position":"FLAT"} (spot sell). Close Short sends {"market":"PERPS","ticker":"...","position":"FLAT"} (perps close). Run separate alerts per asset and timeframe.

As a drop-in module in a strategy: the calculation block is self-contained. It reads from these inputs: atrMode, atrml, atrms, atrlb_long, atrlb_short, lrlb, firstMult. It exports: longStop, shrtStop (stop price levels), xuls, xoss (raw crossover/crossunder), ClsL, ClsS (close signals with two-bar window). Wire ClsL and ClsS into your strategy.close calls. The visuals (regime-colored stop lines, gradient fill, ratchet circles) come with the block.

CLOSE SIGNAL LOGIC
ClsL fires when price crosses under longStop on the current bar, OR when it crossed under on the previous bar and price is still below longStop on the current bar. Same logic inverted for ClsS. This two-bar window catches moves that gap through the stop between bars rather than requiring a strict next-bar confirmation.

SEPARATE LOOKBACKS
Crypto drops faster than it climbs. A shorter lookback for longs (default 14) makes the stop react faster to sudden sell-offs. A longer lookback for shorts (default 26) smooths through the sharp bounces that characterize bear market rallies.

LINEAR REGRESSION PROJECTION
Instead of anchoring the stop to the current close or high/low, LinReg projects one bar ahead based on the recent slope. This positions the stop where price is going, not where it was. Active in A3.1, A4.0, and A4.2.

RATCHET FLOOR
Once the stop moves in your favor, it never pulls back. For longs the stop can only go up; for shorts it can only go down. This locks in gains during a trend and prevents the stop from widening back out during pullbacks. Active in A4.0 and A4.1.

VISUALS
Stop line color reflects the current VWATR relative to its 14-bar EMA: green (longs) / aqua (shorts) when stable, shifting toward amber when expanding. Gradient fill between price and stop intensifies as price approaches the stop level. Ratchet circles (A4.0, A4.1 only) mark each new locked-in level on the stop line.

DASHBOARD
Row 1: active ATR mode, Stop, Gap %. Row 2: LONG stop price and gap % from current price. Row 3: SHORT stop price and gap %. Row 4: ER value (A4.0 only), VWATR as % of price, regime state (EXPANDING / CONTRACTING / STABLE). Dark/light theme, mobile size, and position configurable in settings.

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。