Swing-Weighted Reversal Score (SWRS)

by @zara_flux

Z

Zara Flux

@zara_flux
Open sourceformulaMIT

Scores each qualifying engulfing or pin-bar candle pattern on a 0–100 scale. Pattern quality (wick-to-body ratio, close position within range) contributes 40% of the score; proximity of the pattern's wick tip to the nearest N-bar swing pivot — measured in ATR units — contributes 60%. The proximity bonus decays linearly from maximum at 0.25 ATR to zero at 1.5 ATR. Scores above the threshold are flagged with histogram highlights and optional price-pane markers. Designed for 4H and daily crypto and index swing trading.

0 likes💬 0 comments👁 0 views🔖 0 saves0 forks0 in use
Sign in to interact.

Try it live

Run the preview to see this indicator plotted on a real chart.

Inputs

ATR Lengthint · default 14
Swing Pivot Lookback (bars)int · default 20
Max Proximity ATR Distance (full bonus)float · default 0.25
Proximity Cutoff ATR Distance (zero bonus)float · default 1.5
Pin-Bar Wick-to-Body Minimum Ratiofloat · default 2
Engulfing Body Size Minimum Ratio vs Priorfloat · default 1.2
Signal Score Threshold (0–100)float · default 65

Outputs / plots

SWRS Score (series)Score Threshold (level)Bullish Setup Marker (series)Bearish Setup Marker (series)Bullish SWRS Signal (event)Bearish SWRS Signal (event)

Latest changelog

Initial release.

Version history

v17/24/2026, 1:44:04 PM

Source code

formula
let atr_val = atr(atr_len)
let body = abs(close - open)
let range_hl = high - low
let upper_wick = high - max(open, close)
let lower_wick = min(open, close) - low
let body_ratio = if(range_hl > 0, body / range_hl, 0)
let is_bull_candle = close > open
let is_bear_candle = close < open
let bull_pin = and(lower_wick >= pin_wick_mult * body, upper_wick <= pin_wick_mult * body * 0.5)
let bear_pin = and(upper_wick >= pin_wick_mult * body, lower_wick <= pin_wick_mult * body * 0.5)
let prev_body = abs(shift(close, 1) - shift(open, 1))
let bull_engulf = and(is_bull_candle, and(body >= engulf_mult * prev_body, shift(close, 1) < shift(open, 1)))
let bear_engulf = and(is_bear_candle, and(body >= engulf_mult * prev_body, shift(close, 1) > shift(open, 1)))
let is_bull_pattern = or(bull_pin, bull_engulf)
let is_bear_pattern = or(bear_pin, bear_engulf)
let is_pattern = or(is_bull_pattern, is_bear_pattern)
let close_pos_bull = if(range_hl > 0, (close - low) / range_hl, 0.5)
let close_pos_bear = if(range_hl > 0, (high - close) / range_hl, 0.5)
let close_score_bull = clamp(close_pos_bull, 0, 1)
let close_score_bear = clamp(close_pos_bear, 0, 1)
let wick_ratio_bull = if(body > 0, lower_wick / body, 0)
let wick_ratio_bear = if(body > 0, upper_wick / body, 0)
let wick_score_bull = clamp(wick_ratio_bull / 3, 0, 1)
let wick_score_bear = clamp(wick_ratio_bear / 3, 0, 1)
let pattern_quality_bull = 0.5 * wick_score_bull + 0.5 * close_score_bull
let pattern_quality_bear = 0.5 * wick_score_bear + 0.5 * close_score_bear
let pattern_quality = if(is_bull_pattern, pattern_quality_bull, pattern_quality_bear)
let swing_hi = highest(high, pivot_len)
let swing_lo = lowest(low, pivot_len)
let wick_tip_bull = low
let wick_tip_bear = high
let dist_to_lo_bull = abs(wick_tip_bull - swing_lo)
let dist_to_hi_bear = abs(wick_tip_bear - swing_hi)
let dist_atr_bull = if(atr_val > 0, dist_to_lo_bull / atr_val, 999)
let dist_atr_bear = if(atr_val > 0, dist_to_hi_bear / atr_val, 999)
let prox_raw_bull = clamp((prox_far - dist_atr_bull) / (prox_far - prox_near), 0, 1)
let prox_raw_bear = clamp((prox_far - dist_atr_bear) / (prox_far - prox_near), 0, 1)
let prox_score = if(is_bull_pattern, prox_raw_bull, prox_raw_bear)
let raw_score = 100 * (0.4 * pattern_quality + 0.6 * prox_score)
let swrs = if(is_pattern, raw_score, 0)
let signal = swrs >= threshold
let bull_signal = and(signal, is_bull_pattern)
let bear_signal = and(signal, is_bear_pattern)
plot("swrs", swrs)
plot("threshold_line", threshold)
plot("bull_marker", if(bull_signal, low - 1.5 * atr_val, 0))
plot("bear_marker", if(bear_signal, high + 1.5 * atr_val, 0))
event("bull_setup", bull_signal)
event("bear_setup", bear_signal)

Comments (0)

Sign in to leave a comment.

No comments yet.

Related indicators

Want to use this?

Sign in to preview it live on a chart, fork it into your own Indicators Lab, or use it in a strategy.