MarketFragments Pivot Engine

MarketFragments Pivot Engine — Market Structure Drop
For posting to: Thinkscript Library group (https://www.marketfragments.com/group-page/thinkscript-library). Format matches the diazlaz "Liquidity Sweep Detector — Market Structure Drop" template — short opener, ` What it does`, mechanics-first bullets. Companion paper: Non-Repainting Pivot Detection in ES Futures (MF Strategy Factory) — https://www.marketfragments.com/post/[MAIN_PAPER_SLUG] . Companion LSTM result: *Out-of-Sample Evaluation of Lookback Length as a Predictive Parameter* — https://www.marketfragments.com/post/[LSTM_COMPANION_SLUG] .
Most pivot indicators repaint, skip legs on a single noisy bar, or both — which means the level you anchored a stop to may not be the level the indicator says it is after the next candle prints. This one fits a regression line, ignores slopes too shallow to clear the market's own noise, and switches its sensitivity automatically when the regular session opens or closes. The pivot it draws at confirmation is the pivot it still draws an hour later.
Full methodology, the 9-variant bake-off, the session split, the trail backtest, and the negative results are in the research paper:[Non-Repainting Pivot Detection in ES Futures](https://www.marketfragments.com/post/[MAIN_PAPER_SLUG]) (MF Strategy Factory). The out-of-sample LSTM evaluation of lookback length is in the companion paper: [Out-of-Sample Evaluation of Lookback Length as a Predictive Parameter](https://www.marketfragments.com/post/[LSTM_COMPANION_SLUG])**.
What it does
- Estimates direction by least-squares linear regression of closing price across a configurable lookback window (default `L = 13`).
- Filters small turns with an ATR significance gate: a slope is only allowed to flag a direction change when `|β| > K · ATR`, removing pivots that would otherwise be triggered by single-bar noise.
- Session-switches the gate parameter automatically: tighter during RTH (default `K = 0.15`, optimized for trend/breakout context) and looser during ETH (default `K = 0.05`, optimized for range/support-resistance context). One setting handles both regimes.
- Snaps every confirmed pivot level to an extreme that already printed inside the lookback window. Levels do not move once drawn — strict non-repainting.
- Plots swing-point labels at every completed leg and runs live on-chart statistics for rotation count, swing-verification rate, and average swing size — the same calculations used in the research paper.
How it fires
- A pivot confirms when the regression slope sign changes (positive → negative gives a confirmed high; negative → positive gives a confirmed low), conditional on the gate condition being satisfied.
- At confirmation the level snaps to the high (or low) extreme within the trailing lookback window; the support/resistance line is drawn there and never modified.
- Inherent confirmation latency is approximately `L` bars (a function of the regression window). A separate cosmetic forward-aligned layer is used for marker placement only and is never used for signal logic, levels, or stats.
How to read it
- If the session label on the chart says RTH, treat the level as a breakout / trend pivot — price tends to run through it. Use it for momentum continuation and trend-anchored stops.
- If the session label says ETH, treat the level as a fade / support-resistance pivot — overnight price tends to revisit and reject it. Use it for mean-reversion entries and range-bound trade structure.
- The label is the use-case. Same engine, two operational modes, switched by the bar timestamp.
Validation notes
- Behavior validated on approximately 5 years of ES 5-minute continuous contract data (unadjusted) for the principal slope/gate/session sweeps.
- Confirmed pivot levels are non-repainting; level-repaint match measured at 100% with the gate at `K ≥ 0.10`.
- Swing-verification rate at the released gate setting (`K=0.10`): **81.03% in RTH (n=3,543)** and **75.73% in ETH (n=8,025)**. Two-proportion z ≈ 6.6, p < 0.001 against the null of session-invariance.
- No claim of harmonic-pattern performance is made by this indicator. What was validated are pivot-stream properties: non-repainting, fast confirmation latency, robust leg registration under noise, low per-bar compute, and session-conditioned behavior. The performance of any specific pattern, strategy, or signal built on top of these pivots is a separate evaluation problem.
Note: Subscribers have access complete end to end Harmonic strategy.
- A separate out-of-sample LSTM evaluation across lookback lengths 6–25 found no length at which pivot geometry predicts the next move above chance in either session — directional accuracy in [0.4939, 0.5126] across all 20 lengths in RTH, [0.4975, 0.5101] in ETH, with 95% CI including 0.50 at every length. Lookback length is therefore a responsiveness dial, not a tuned hyperparameter. Shorter `L` produces more pivots confirmed at lower latency; longer `L` produces fewer pivots representing larger structural legs. Pick the length to match the downstream consumer's requirement.
Files
- `MarketFragments_PivotEngine.ts` — the live ThinkScript study
- Research CSVs and Python source: see the principal paper [*Non-Repainting Pivot Detection in ES Futures*]https://www.marketfragments.com/post/mf-strategy-factory-main-pivot-engine-paper
- LSTM length-sweep evaluation: [*Out-of-Sample Evaluation of Lookback Length as a Predictive Parameter*]https://www.marketfragments.com/post/mf-strategy-factory-pivot-engine-lstm-companion
- More from this series: [MF Strategy Factory category index](https://www.marketfragments.com/blog/categories/mf-strategy-factory).
Research preview. Not financial advice. Figures are from historical study and are not a promise of future results.
© MarketFragments.com Research Team. Free for educational and research use. Source: Market Fragments MF Strategy Factory | marketfragments@gmail.com

