$npx -y skills add SKE-Labs/agent-trading-skills --skill mean-reversionTest whether a price or spread reverts toward a modeled center. Use when evaluating stationarity, half-life, z-score bands, regime breaks, time stops, and net execution costs.
| 1 | # Mean Reversion |
| 2 | |
| 3 | Mean reversion is a hypothesis that a specified price/spread process returns toward a modeled center fast enough to overcome costs. Verify stationarity or stable conditional behavior before trading; an individual price level may trend indefinitely. |
| 4 | |
| 5 | ## Detection Methods |
| 6 | |
| 7 | ### Z-Score |
| 8 | |
| 9 | `Z-Score = (Series - rolling mean) / rolling standard deviation`. Select the series, lookback, entry/exit bands, and time stop in training data. A z-score is descriptive and is not normally distributed by assumption. |
| 10 | |
| 11 | | Z-Score | Signal | |
| 12 | | --- | --- | |
| 13 | | Positive extreme | Candidate short only if reversion model passes | |
| 14 | | Near center | No new extreme under the chosen rule | |
| 15 | | Negative extreme | Candidate long only if reversion model passes | |
| 16 | |
| 17 | ### Bollinger Band Method |
| 18 | |
| 19 | - Band touch/pierce + reversal candle → trade toward middle band |
| 20 | - Test band, RSI, and reversal features for incremental value; they are correlated price transforms |
| 21 | |
| 22 | ### RSI Extreme Method |
| 23 | |
| 24 | Calibrate RSI percentiles/bands to the instrument and regime; no fixed threshold creates a buy or sell. |
| 25 | |
| 26 | ## Regime and Stationarity Gate |
| 27 | |
| 28 | Use an objective, calibrated regime/stationarity gate. ADX can be one feature but does not establish mean reversion or set size. |
| 29 | |
| 30 | ## Workflow |
| 31 | |
| 32 | 1. **Check regime** (must pass first): |
| 33 | ``` |
| 34 | get_indicators(indicator_code="dmi", symbol=<symbol>, exchange=<exchange>, interval=<interval>) |
| 35 | ``` |
| 36 | Apply the frozen regime and stationarity gates; return `no trade` when either fails. |
| 37 | |
| 38 | 2. **Get BB and RSI**: |
| 39 | ``` |
| 40 | get_indicators(indicator_code="bbands", symbol=<symbol>, exchange=<exchange>, interval=<interval>) |
| 41 | get_indicators(indicator_code="rsi", symbol=<symbol>, exchange=<exchange>, interval=<interval>) |
| 42 | get_indicators(indicator_code="ema", symbol=<symbol>, exchange=<exchange>, interval=<interval>) |
| 43 | ``` |
| 44 | |
| 45 | 3. **Get candles** for confirmation: |
| 46 | ``` |
| 47 | get_candles_around_date(symbol=<symbol>, exchange=<exchange>, interval=<interval>, date=<date>) |
| 48 | ``` |
| 49 | |
| 50 | 4. **Mark setup**: |
| 51 | ``` |
| 52 | draw_chart_analysis(action="create", drawing={ |
| 53 | "type": "demand", |
| 54 | "points": [ |
| 55 | {"time": <extreme_time>, "price": <lower_bb>}, |
| 56 | {"time": <current_time>, "price": <entry_zone>} |
| 57 | ], |
| 58 | "options": {"text": "Mean Reversion Buy (RSI: 22, Z: -2.3)"} |
| 59 | }) |
| 60 | ``` |
| 61 | |
| 62 | 5. **Exits**: predeclare center, partial-center, opposite-band, stop, and maximum-holding-time variants; retain only net-positive held-out logic without universal win rates. |
| 63 | |
| 64 | ## Evidence and Validation |
| 65 | |
| 66 | - Treat the setup as a testable hypothesis, not a prediction. Define thresholds, entry, invalidation, and exit before evaluating outcomes. |
| 67 | - Calibrate on the same instrument, venue, session, and timeframe. Use closed candles and a held-out or walk-forward sample; record every variant tried. |
| 68 | - Include spread, fees, slippage, borrow or funding, partial fills, and latency. Reject the setup when net expectancy is not positive or depends on one narrow parameter. |
| 69 | - Return observed inputs, missing data, cost assumptions, entry, invalidation, exit, and a valid, watch, or no-trade status. |
| 70 | - Research basis: Mean reversion is a model assumption, not a universal property. [Optimal mean-reversion research](https://arxiv.org/abs/2003.10502) derives thresholds under an Ornstein–Uhlenbeck process; verify that the spread is stationary before applying them. |
| 71 | |
| 72 | ## Key Rules |
| 73 | |
| 74 | - Never assume a series mean reverts; verify the process and monitor parameter/stationarity breaks. |
| 75 | - NEVER enter on BB touch alone; require confirmation candle (engulfing, hammer, doji) |
| 76 | - Compare center and opposite-band exits rather than assigning realism beforehand. |
| 77 | - A squeeze is compression, not proof that a breakout is coming. |
| 78 | - Do not count BB, RSI, and z-score as independent confirmation. |
| 79 | - Use a time stop tied to estimated half-life and exit on a stationarity/regime break. |
| 80 | - If price is at lower BB due to fundamental repricing (earnings, news), it is not "oversold" |
| 81 | |
| 82 | ## Related Skills |
| 83 | |
| 84 | - **bollinger-bands** — BB touches are the primary visual mean reversion signal |
| 85 | - **market-regime-detection** — supply a calibrated regime feature and uncertainty state |