OPEN-SOURCE SCRIPT

Compression Shift Index [JOAT]

721
Compression Shift Index [JOAT]

Introduction

Compression Shift Index is an open-source Pine Script v6 indicator designed to detect transitions between compression and displacement. It measures whether price is storing energy in a tight state, whether that energy is beginning to release directionally, and whether the release is supported by enough pressure and travel efficiency to matter.

The problem this indicator solves is timing. Traders often recognize trend after the move is already mature, or they chase weak momentum bursts that never become true displacement. Compression Shift Index is built to distinguish between quiet compression, directional pressure, and confirmed shift conditions so the user can see whether price is merely active or whether a real state change is underway.

The script lives in its own pane, but it also projects tactical shift ranges onto the main chart. That means it can work as both a state engine and a visual execution aid. The pane handles classification and scoring. The overlay range preserves the high, low, and midpoint of the most recent active shift so price can be read against the trigger zone directly on the chart.

Rather than relying on one oscillator reading, the script blends moving-average spread, RSI of momentum, ATR expansion, path efficiency, and compression mathematics. The result is not a conventional trend tool. It is a state-transition tool built to show when stored pressure is becoming directional opportunity.

snapshot

Core Concepts

1. Compression Score

Compression is measured by comparing the recent price range to ATR-normalized movement over a configurable window. As the range contracts relative to expected volatility, the compression score rises.

Pine Script®
float compressionRatio = safeDiv(ta.highest(high, compressionLength) - ta.lowest(low, compressionLength), ta.atr(compressionLength) * compressionLength) * 100.0 float compressionScore = clamp(100.0 - compressionRatio, 0, 100)


This means the script is not labeling compression by candle size alone. It evaluates the market relative to its own volatility conditions.

2. Displacement Score

Displacement is measured through moving-average spread magnitude, RSI-based pressure away from neutrality, and fast-versus-slow ATR expansion. A high displacement score means price is no longer just compressed. It is pushing with enough directional force to deserve attention.

3. Pressure Confirmation

Directional pressure requires more than a large reading. Bullish pressure needs positive spread and price acceptance above the fast EMA. Bearish pressure requires the opposite. This creates a separation between raw movement and directional pressure that is actually aligned with the current path of price.

4. Shift Range Memory

When a confirmed bull or bear shift occurs, the script stores the initiating bar’s high and low, then extends that range for a configurable number of bars. As new bars arrive, the active range updates its upper and lower boundaries.

This transforms the shift from a momentary signal into a tactical map. The trader can judge whether price is holding inside the shift range, stretching away from it, or failing back through the structure.

5. Quality And Travel Efficiency

Not every shift is equal. The script measures path efficiency by comparing net travel to the cumulative path traveled across the efficiency window. That helps distinguish efficient directional release from noisy back-and-fill movement.

When displacement, pressure, and efficiency all align, the quality score rises. This is especially useful for separating impulsive continuation from unstable burst behavior.

snapshot

Features

  • Compression and displacement state engine: Differentiates quiet conditions from directional release
  • Bull and bear shift detection: Confirms directional shifts only after displacement and pressure criteria align
  • Tactical overlay range: Projects the active shift high, low, and midpoint onto the main chart
  • Ribbon bias display: Adds a visual ribbon showing directional pressure inside the pane
  • Travel efficiency scoring: Measures whether displacement is clean or noisy
  • State backdrop and candle tinting: Tints both pane and chart context according to the current state
  • Detailed dashboard: Publishes compression, displacement, ATR ratio, heat, range, stretch, velocity, efficiency, quality, and persistence
  • Confirmed-bar alerts: Includes compression, bull shift, bear shift, pressure, release, fade, and quality-state alerts
  • Data-window exports: Makes many internal scores accessible without adding extra plots to the pane
  • Range-aging logic: Tracks how long the active shift has been in effect


Visual Elements

  • Pane state curves: The net shift, compression, and displacement lines provide a layered read of current state
  • Ribbon bias fill: The pane ribbon helps show whether directional pressure is leaning bullish or bearish before full shift confirmation
  • Overlay shift range: The active high, low, and midpoint are projected onto the price chart for tactical context
  • Backdrop and candle tinting: The indicator colors both pane and chart state to make transitions easier to identify at a glance
  • Dashboard diagnostics: The top-right panel summarizes metrics that would otherwise require several separate indicators


Best Practices

  • Wait for displacement to dominate compression before assuming a move has truly released
  • Use high-quality shifts as higher-priority context than low-efficiency state changes
  • Read the active shift range as a tactical map, not as a guarantee that price will respect every boundary
  • If pressure improves but displacement remains weak, treat the move as developing rather than already established
  • Use the state engine to filter your existing entries instead of trying to trade every alert in isolation


Input Parameters

Signal Engine:
  • Fast MA Length: Sets the fast trend reference
  • Slow MA Length: Sets the slow trend reference
  • Compression Window: Defines the state lookback for range contraction
  • RSI Length: Sets the smoothing period for momentum pressure evaluation
  • Momentum Length: Defines the raw momentum lookback


Thresholds:
  • Compression Threshold: Determines how compressed the market must be to count as compressed
  • Displacement Threshold: Determines how forceful the move must be to count as a shift
  • Shift Hold Bars: Controls how long the active shift range remains alive
  • Efficiency Length: Sets the path-efficiency lookback
  • Show Trigger Range: Toggles the projected overlay range on the chart


Visual Language:
  • Bull and bear color pairs
  • Neutral color and panel background
  • Show Dashboard toggle
  • Show State Backdrop toggle
  • Show State Ribbon toggle


How to Use This Indicator

Step 1: Identify The Current State
Start with the dashboard and pane. If compression is dominant, the market is still storing energy. If bull or bear pressure is present, directional force is building. If a bull or bear shift is confirmed, the state transition has already occurred.

Step 2: Compare Compression To Displacement
The most useful read is not the absolute number alone, but the relationship between compression and displacement. When compression is high and displacement is still low, the market is coiled. When displacement overtakes compression, the release phase is gaining control.

Step 3: Use The Active Shift Range
Once a shift is active, watch the projected upper, lower, and midpoint lines on the main chart. These define the tactical zone created by the displacement event. Price behavior around that range often provides better context than the signal bar alone.

Step 4: Check Quality And Efficiency
A high-quality state means the release is not only directional but also relatively efficient. If quality is weak, treat the shift more cautiously because the move may be noisy or unstable.

Step 5: Use It As A State Filter
Compression Shift Index is most effective as a state filter for your own process. It can help you avoid forcing breakout logic during compression and avoid fading a move that is still in active displacement.

Indicator Limitations

  • Compression does not guarantee that a strong displacement event will follow immediately
  • A shift can fail quickly if the broader market context does not support follow-through
  • Travel efficiency can lag during early release phases because noisy price action is still being absorbed into the lookback
  • The active shift range is a tactical reference zone, not an automatic support or resistance guarantee


Originality Statement

Compression Shift Index is original in the way it turns compression, displacement, pressure, efficiency, and range memory into one unified transition model. It is not simply an oscillator blend for cosmetic effect:

  • It frames compression and release as a state transition rather than a single threshold cross
  • It preserves the originating shift range on the main chart, which links pane analysis to execution context
  • It includes efficiency and velocity metrics that help separate orderly displacement from noisy expansion
  • It uses a dashboard that summarizes the full state stack rather than forcing the user to infer everything from one line


Disclaimer

This indicator is provided for educational and informational purposes only. It is not financial advice or a recommendation to buy or sell any financial instrument. Compression and displacement readings describe market state, not guaranteed future direction. Markets can remain compressed longer than expected or reverse immediately after a shift appears. Always use independent judgment and proper risk management.

-Made with passion by jackofalltrades

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.