OPEN-SOURCE SCRIPT

S/R Flip Detector [Alpha Confirmed]

978
INDICATOR DOCUMENTATION
S/R Flip Detector [Alpha Confirmed]
Horizontal support & resistance with alpha-scored resistance-to-support flip detection
Pine Script v5 | Overlay Indicator | Based on Kakushadze (2016) quantitative alpha research
Overview
Most support and resistance indicators stop at identifying price levels. This one goes a step further: it scores each level against six quantitative alpha signals to determine whether a resistance zone has genuinely converted into support — or whether it is merely testing the level before rejecting again.
The distinction matters enormously in practice. A stock returning to a prior resistance level after breaking above it can either be a high-conviction buy (the flip is confirmed, institutions are accumulating at the level) or a trap (the stock is failing to hold, distribution is present, and the level will reassert as resistance). Raw price structure alone cannot tell you which scenario is unfolding. Alpha confirmation can.
The six confirmation signals are derived from 101 Formulaic Alphas by Kakushadze (2016), a widely cited quantitative finance paper that catalogues systematic alpha factors for equity trading. Each signal was selected specifically because it captures a dimension of market behavior that is meaningfully different from the others — together they form a multi-layered confirmation framework.

How It Works
Step 1 — Pivot Detection
The indicator uses Pine Script's built-in ta.pivothigh() and ta.pivotlow() functions to identify structurally significant price points. A pivot high at bar i means the high at that bar was the highest point within ±pivot_left bars on the left and ±pivot_right bars on the right. These are the swing highs and swing lows that form the skeleton of price structure.
Step 2 — Zone Clustering
Individual pivots that fall within atr_merge × ATR(14) of each other are merged into a single zone. This prevents the same price level from appearing as three separate zones at slightly different prices. The zone stores its representative price (running mean of all member pivots), upper and lower bounds, total touch count, and a breakdown of how many touches were pivot highs versus pivot lows.
Step 3 — Classification
Each zone is classified on every bar as one of four types:

★ FLIPPED Was resistance (≥2 pivot high touches), price held above it, and has returned from above with alpha score ≥ threshold
◎ FLIP? Price structure confirms a flip but alpha score is below the minimum threshold — watch closely
SUP Zone is below current price with predominant pivot low touches
RES Zone is above current price with predominant pivot high touches

Step 4 — The Flip Condition
A zone qualifies as FLIPPED when all four of the following structural conditions are simultaneously true:
• Prior resistance: The zone has at least 2 pivot high touches, and the price approaching the zone historically came from below.
• Breakout and hold: Price has closed above the zone's upper bound on at least 2 consecutive bars — confirming acceptance, not a wick through.
• Return to zone: Price has subsequently come back to within 1 ATR of the zone from above — testing whether it now holds as support.
• Alpha confirmation score: At least 2 of the 6 alpha signals are actively confirming the flip (configurable).

Step 5 — Alpha Scoring
When price is near a zone, six alpha signals are evaluated against the current bar. Each signal that passes its threshold contributes 1 point to the zone's confirmation score (maximum 6). The score is preserved at the highest value seen while price was near the zone.

The Six Alpha Confirmation Signals
Each signal was chosen because it captures a distinct dimension of what a genuine resistance-to-support flip looks like from an institutional and quantitative perspective.

Alpha Signal Threshold Direction What It Confirms
43 high_vol_washout > 0.55 Bullish Volume surging at the zone on the retest. High percentile-ranked volume on a prior price decline — the hallmark of capitulation and institutional absorption.
101 candle_body_strength > 0.30 Bullish Price closing well above the open at the zone. A strong candle body means acceptance, not just a wick through. Buyers are in control at end-of-day.
34 calm_dip_reversion > 0.55 Bullish Short-term volatility compressing relative to medium-term volatility at the zone, combined with a recent close decline. The market is coiling quietly — a healthy retest pattern.
9 trend_regime_switch > 0.0 Bullish The 5-day price delta pattern is net positive. All recent daily moves agree directionally. The macro context supports the flip holding.
53 stochastic_decay > 0.0 Bullish The stochastic ratio (close position within the high-low range) has been deteriorating — meaning sellers have been progressively exhausted at this level.
3 discount_accumulation > 0.30 Bullish Opening prices and volume are negatively correlated over the past 10 bars — the signature of institutions buying at discounted opens. Smart money is present at the level.

NOTE Alpha 43 and Alpha 3 are the highest-conviction individual signals. A zone with both firing simultaneously — high-volume washout combined with institutional discount accumulation — represents the strongest possible confirmation of a genuine flip.


Reading the Chart
Zone Boxes
Each identified zone is drawn as a coloured box spanning its price range, extending to the right for a configurable number of bars. The box colour immediately communicates the zone type:
• Bright green (solid border): Confirmed flip — resistance that has converted to support with alpha confirmation. Highest priority.
• Dim green: Potential flip — price structure suggests a flip but alpha score is below the minimum threshold. Watch for score to rise.
• Blue: Active support zone — price is above the zone with predominant pivot low touches.
• Red: Active resistance zone — price is below the zone with predominant pivot high touches.

Zone Labels
Each box carries a label showing the zone type, representative price, touch count breakdown (H = pivot highs, L = pivot lows), and alpha score (e.g. [4/6]). Labels appear to the right of the most recent bar and update in real time.
Green Background
When the current bar is within proximity of a confirmed flip zone, the candle background turns a soft green. This is a real-time alert that price is at an actionable level — no need to scan visually for relevant zones.
Alpha Signal Table
A compact table in the bottom-right corner displays the live value of all six alpha signals with a ✓ or · pass indicator and the total score. This lets you verify at a glance what is driving (or preventing) a zone's confirmation score on the current bar.

Settings Reference
Zone Detection

Setting Default Description
Pivot lookback 10 Bars to the left that must be lower (for a pivot high) to qualify the point as a significant swing.
Pivot lookforward 10 Bars to the right that must be lower to confirm the pivot. Note: this means pivots are confirmed 10 bars after they form.
Min touches 2 Minimum number of pivot contacts required to form a meaningful zone. Increase to 3 for higher-conviction levels only.
Zone merge width 0.5× Two pivots within this fraction of ATR(14) are merged into one zone. Increase if you see too many adjacent zones.
Near-zone proximity 1.0× Price must be within this many ATRs of a zone to trigger alpha scoring and background highlighting.
Max zones 10 Maximum number of zones tracked simultaneously. Oldest zones are dropped when this limit is reached.

Flip Detection

Setting Default Description
Min alpha score 2 Minimum number of the 6 alpha signals required to classify a flip as confirmed. Raise to 3-4 for stricter confirmation. Lower to 1 for more sensitivity.
Resistance lookback 60 How many bars back to examine when determining whether a zone was acting as resistance historically.

Alpha Thresholds

Setting Default Description
43_ vol washout 0.55 Percentile rank threshold for the volume-washout signal. Higher values require more extreme volume surges.
101_ candle body 0.30 Fraction of the high-low range that the close-open difference must exceed. 0.30 means the candle body is 30%+ of the full range.
34_ calm dip 0.55 Percentile rank threshold for the volatility compression signal.
3_ discount accum 0.30 Correlation threshold for the institutional accumulation signal.

Display

Setting Default Description
Show Support zones On Toggle blue support zone boxes.
Show Resistance zones On Toggle red resistance zone boxes.
Show Flipped zones On Toggle confirmed flip zones.
Show unconfirmed flips On Toggle potential flip zones (score below threshold).
Show alpha scores On Display the [X/6] score on zone labels.
Extend zones right 40 How many bars to extend zone boxes to the right of the last bar.
Highlight near-flip bars On Green background when price is near a confirmed flip zone.


Alerts
Two built-in alert conditions are included, configurable from the TradingView Alerts panel:

ALERT 1 Near Confirmed Flip Zone — fires when the current bar is within proximity of a zone classified as a confirmed resistance-to-support flip. This is the primary trade signal alert.

ALERT 2 Alpha Confirmation Score Met — fires when the overall alpha score for the current bar crosses the minimum threshold. Use this as a secondary confirmation that conditions are favourable even outside a specific zone.

To set an alert: right-click the indicator name on the chart → Add Alert → select the condition from the dropdown.

Suggested Usage
Timeframes
The indicator performs well on daily and 4-hour charts where pivots have structural significance. On daily charts, increase the pivot window to 12–15 bars to capture only major S/R levels. On intraday (1H and below), reduce the window to 5–7 and lower the min-touches requirement to 2.
Entry Framework
A confirmed flip zone provides a defined entry area, not a specific entry price. The suggested approach is:
• Wait for the zone label: Price must return to within 1 ATR of the zone after breaking above it.
• Check the alpha table: Ideally 3+ signals should be green when price is at the zone.
• Entry trigger: Enter on a strong candle body (101_ > 0.40) closing at or above the zone's midpoint.
• Stop placement: Below the zone's lower bound. If price closes below the zone, the flip has failed.
• Target: Prior swing high or next resistance zone above.
Filtering False Flips
Not every confirmed flip leads to a continuation. The most common failure mode is when distribution signals (vol_amplified_dist) are present alongside the flip — this means institutions are selling into the recovery rather than buying the dip. If you see the zone confirm but the alpha table shows the stochastic and accumulation signals failing, treat the zone as lower conviction and size accordingly.
Timeframe Alignment
The most reliable setups occur when a flip zone on the daily chart aligns with a flip zone on the weekly chart — price is returning to a level that has multi-timeframe structural significance. Open the indicator on both timeframes and look for zones at similar price levels.

Technical Notes
Pine Script Constraints
Because Pine Script processes bars sequentially from left to right, zone classification is built incrementally as pivots are detected. A pivot is only confirmed pivot_right bars after it forms — which means confirmed pivots appear with a lag. On a daily chart with the default setting of 10, a pivot from 10 days ago is classified today. This is inherent to Pine Script's architecture and cannot be avoided; it does not affect the quality of zones, only their discovery timing.
Zone Memory
Zones are stored in Pine Script var arrays that persist across bars. When the max_zones limit is reached, the oldest zone is dropped from the front of the array. If you need to track more historical levels, increase max_zones up to 30. Note that higher values may slow rendering on very long chart histories.
Alpha Approximations
The six alpha signals in this indicator are time-series implementations of cross-sectional factors from Kakushadze (2016). In the original paper, rank() refers to a cross-sectional percentile rank across all stocks in the universe on a given day. In a single-ticker Pine Script context, rank() is approximated using ta.percentrank() — the percentile position of the current value within its own recent history. This approximation is directionally consistent with the original formulation and effective in practice, but users should be aware it is not identical to a true cross-sectional computation.

Academic Foundation
The six alpha signals in this indicator are derived from "101 Formulaic Alphas" by Zura Kakushadze (2016), published in Wilmott Magazine. The paper provides a systematic catalogue of alpha factors used in quantitative equity trading, each expressed as a mathematical formula over price, volume, and VWAP series.
The specific alphas used here were selected from that catalogue based on their interpretability in the context of price-level confirmation, their coverage of distinct market dimensions (volume, momentum, volatility, institutional flow), and their empirical behaviour at support/resistance zones in back-testing across multiple equity universes.
This indicator does not replicate the full cross-sectional ranking methodology from the paper — it applies the factor formulas in a single-ticker time-series context as confirmation signals rather than return predictors. Users interested in the full methodology should refer to the original paper.

S/R Flip Detector [Alpha Confirmed] · Pine Script v5 · Kakushadze (2016)
For educational purposes. Not financial advice.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.