// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © realanthonyc https://www.tradingview.com/u/realanthonyc
//@version=6
// -----------------------------------------------------
// Magic Sequential 9 with ATR Filter
// v1.1.0
// -----------------------------------------------------
indicator("Magic Sequential 9", shorttitle = "Magic 9", overlay = true, precision = 0, max_labels_count = 500)
// === Inputs ===
use_filter = input.bool(true, title = "Filter Flat Trends")
atr_mult = input.float(0.05, title = "Filter Sensitivity", minval = 0.005, step = 0.005, tooltip = "Higher value means stricter filter. The sequence only starts or continues when price momentum exceeds this volatility threshold.")
// === Colors ===
col_up_light = #ee9999
col_up_strong = #d10e00
col_down_light = #98d39b
col_down_strong = #00a105
// === Core Logic ===
float threshold = use_filter ? ta.atr(14) * atr_mult : 0.0
int up_count = ta.barssince(not (close > close[4] + threshold)) + 1
int down_count = ta.barssince(not (close < close[4] - threshold)) + 1
// === Plotting ===
plotchar(up_count == 7 ? 7 : na, char = '⁷', location = location.abovebar, color = col_up_light, size = size.tiny)
plotchar(up_count == 8 ? 8 : na, char = '⁸', location = location.abovebar, color = col_up_light, size = size.tiny)
plotchar(up_count == 9 ? 9 : na, char = '⁹', location = location.abovebar, color = col_up_strong, size = size.tiny)
plotchar(down_count == 7 ? 7 : na, char = '₇', location = location.belowbar, color = col_down_light, size = size.tiny)
plotchar(down_count == 8 ? 8 : na, char = '₈', location = location.belowbar, color = col_down_light, size = size.tiny)
plotchar(down_count == 9 ? 9 : na, char = '₉', location = location.belowbar, color = col_down_strong, size = size.tiny)