OPEN-SOURCE SCRIPT
Double ATR Reversal

// ════════════════════════════════════════════════════════════════════════════
// DOUBLE ATR REVERSAL — Chandelier-style trailing stop + ATR expansion scanner
// ────────────────────────────────────────────────────────────────────────────
// METHOD
// 1. Trailing stop. A ratcheting stop is computed from the rolling extreme
// (highest src_h or lowest src_l over N bars) offset by a multiple of
// Wilder's ATR. The long stop only ratchets up; the short stop only
// ratchets down. When price crosses the opposite side's stop, the
// trend "flips." This is the same construction as the standard
// Chandelier Exit; the "Double ATR" naming refers to the default
// multiplier of 2.0 (faster reversals than the conventional 3.0).
//
// 2. Reversal events. A bull reversal fires on the bar where the trend
// flips from -1 to +1; a bear reversal on +1 to -1. These are
// point-in-time events, distinct from the persistent trend state.
//
// 3. Volatility expansion overlay. Current ATR is compared to a rolling
// SMA of ATR over `expand_len` bars. A separate signal fires when
// current ATR exceeds expand_mult × baseline. This catches news /
// volatility events that are independent of trend direction and is
// the primary addition over a plain trailing-stop indicator.
//
// SOURCE TOGGLE
// `use_close` selects whether the rolling extremes use closing prices
// (smoother, fewer whipsaws) or wicks (more sensitive to spikes). This
// meaningfully changes signal frequency on noisy instruments and is
// exposed as an input rather than hard-coded.
//
// OUTPUTS
// • Trailing stop line, color-coded by trend state
// • Optional bar coloring by trend
// • Bullish / bearish reversal triangles + optional price-annotated labels
// • Yellow background flash + diamond marker on ATR expansion bars
// • Info table: trend, ATR (absolute and as % of price), trail stop,
// multiplier, and expansion state
// • Four alertconditions: bull reversal, bear reversal, any reversal,
// and volatility expansion — suitable for cross-symbol scanning via
// TradingView alert lists
//
// NOT A STRATEGY: orders, slippage, and returns are not modeled.
// ════════════════════════════════════════════════════════════════════════════
// DOUBLE ATR REVERSAL — Chandelier-style trailing stop + ATR expansion scanner
// ────────────────────────────────────────────────────────────────────────────
// METHOD
// 1. Trailing stop. A ratcheting stop is computed from the rolling extreme
// (highest src_h or lowest src_l over N bars) offset by a multiple of
// Wilder's ATR. The long stop only ratchets up; the short stop only
// ratchets down. When price crosses the opposite side's stop, the
// trend "flips." This is the same construction as the standard
// Chandelier Exit; the "Double ATR" naming refers to the default
// multiplier of 2.0 (faster reversals than the conventional 3.0).
//
// 2. Reversal events. A bull reversal fires on the bar where the trend
// flips from -1 to +1; a bear reversal on +1 to -1. These are
// point-in-time events, distinct from the persistent trend state.
//
// 3. Volatility expansion overlay. Current ATR is compared to a rolling
// SMA of ATR over `expand_len` bars. A separate signal fires when
// current ATR exceeds expand_mult × baseline. This catches news /
// volatility events that are independent of trend direction and is
// the primary addition over a plain trailing-stop indicator.
//
// SOURCE TOGGLE
// `use_close` selects whether the rolling extremes use closing prices
// (smoother, fewer whipsaws) or wicks (more sensitive to spikes). This
// meaningfully changes signal frequency on noisy instruments and is
// exposed as an input rather than hard-coded.
//
// OUTPUTS
// • Trailing stop line, color-coded by trend state
// • Optional bar coloring by trend
// • Bullish / bearish reversal triangles + optional price-annotated labels
// • Yellow background flash + diamond marker on ATR expansion bars
// • Info table: trend, ATR (absolute and as % of price), trail stop,
// multiplier, and expansion state
// • Four alertconditions: bull reversal, bear reversal, any reversal,
// and volatility expansion — suitable for cross-symbol scanning via
// TradingView alert lists
//
// NOT A STRATEGY: orders, slippage, and returns are not modeled.
// ════════════════════════════════════════════════════════════════════════════
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.