Chart gallery and technical writeup for two independent quantitative-trading research projects by James Sawyer (jsawyerdev):
- theil-sen-chop-lab — a robust-regression trend/chop classifier for hourly commodity price windows.
- sr-breakout-signal — a support/resistance breakout early-warning signal built on change-point segmentation and Theil-Sen line fitting.
Both projects share a lineage: they are standalone, runnable extractions of
statistics used inside a larger multi-agent commodities trading system
(consensus-trading-stack), built and backtested by James Sawyer against ~3 years
of real Dukascopy hourly OHLC data across Gold, Silver, Oil (WTI Crude), Oil (Brent),
and Natural Gas.
This repo exists purely to host and explain the generated chart output of both projects — the code, tests, and full statistical methodology live in their own repositories.
A robust trend-and-chop measurement tool, by James Sawyer, that answers — for any window of hourly commodity candles — which way price trended, how choppy it was, and how confidently either statement can be made.
- Fit a robust trend line. A Theil-Sen estimator (
scipy.stats.theilslopes,method="joint") fitsprice = slope * bar_index + interceptthrough each bar's typical price(high + low) / 2. The slope is the median of all pairwise slopes between points, giving it a ~29% breakdown point — a single flash-crash wick barely moves the line, unlike an ordinary least-squares fit that gets dragged toward outliers. - Count crossings, with a deadband. Each close's residual against the line is tested against a deadband set at 25% of the window's own median absolute residual, so the statistic is scale-free across instruments with wildly different price levels. A bar inside the deadband carries the previous side forward instead of splitting a run.
- Count close-to-close reversals. A magnitude-blind
swing_densitystatistic counts sign changes between consecutive closes, catching whipsaw behavior that a magnitude-weighted path-efficiency score would hide. - Label the window. Direction (
rising/falling/flat) comes from the Theil-Sen slope against a noise band; chop band (trending/mixed/choppy) comes from the reversal count, calibrated so a 20-bar window's random-walk null (9 reversals) sits inside themixedband rather than at an arbitrary edge.
On the source system's development replay, the < 6 reversal band scored +0.0522
R/trade, 6–10 scored +0.0013, and > 10 scored −0.0473 — monotonic across
all three, which is the only threshold in this tool that is asserted as measured
rather than descriptive.
Every per-window figure has three stacked panels:
- Top — closes (black), the typical price used for the fit (grey dashed), the Theil-Sen line (blue) with its shaded deadband, points colored green above / orange below the line, and dotted purple verticals marking confirmed crossings.
- Middle — each close's residual against the line, with the deadband shaded — the panel that makes a crossing visually unambiguous.
- Bottom — close-to-close changes, with an
xmarking every reversal the flip count registered.
Aggregate distributions of both chop statistics (crossing-based and reversal-based) across an entire random sample of 20-bar windows drawn from the Dukascopy hourly archive (BRENT, CRUDE, GOLD, NATGAS, SILVER; 2023-07 to 2026-07).
Eight windows sampled and rendered from the same run, spanning every direction/chop combination the labeling scheme produces:
Each filename encodes <index>_<direction>-<chop band>_<symbol>_<window end timestamp>,
generated deterministically from a fixed random seed so every run is reproducible.
An early-warning support/resistance breakout signal, by James Sawyer, built on change-point segmentation and robust line fitting, backtested with full statistical rigor (significance testing, real cost modeling, regime conditioning, and a 250-cell parameter sweep) rather than reported on raw hit rate alone.
- Run PELT change-point detection (
ruptures, L2 cost) separately on a window's low prices and high prices. - Take each detected segment's minimum (low series) or maximum (high series) as a candidate support/resistance pivot, keeping only pivots clustered near that side's own price extreme.
- Fit a Theil-Sen robust line through each side's surviving pivots.
- Compare pivot counts between sides. If price sits within a volatility-scaled
tolerance band ("a whisper") of the side with more pivots, fire a directional
bias. Two mirror-image theses assign that bias oppositely:
- Coiled spring (shipping default): the dominant side is failing to break —
dominant support →
likely_long, dominant resistance →likely_short. - Persistent pressure (alternative): repeated tests are the pressure —
dominant resistance →
likely_long, dominant support →likely_short.
- Coiled spring (shipping default): the dominant side is failing to break —
dominant support →
- Confidence is the pivot-count asymmetry between the two sides, scaled
0.0–1.0.
Bottom line from the full investigation: across 60+ symbol/side/thesis/regime/ parameter combinations tested, exactly one result is both statistically significant after Bonferroni correction (p = 0.004) and net-profitable after real recorded spread (+23.4 bps/trade) — Natural Gas, persistent-pressure thesis, long side, window = 20h / horizon = 8h. Everything else is indistinguishable from chance or unprofitable after costs.
Six small-multiple panels built from deterministic synthetic scenarios: support- and resistance-defended consolidations, each paired with a correctly predicted breakout, a broken-level case, and a random-walk null control. All four directional panels fire the correct bias; the null control and broken-level case correctly abstain.
Edge over the market base rate for every symbol/side pair, backtested against ~3 years of real hourly OHLC (window = 20h, horizon = 8h, non-overlapping trades, ≥100 signals per cell), with 95% Wilson confidence intervals. 6 of 10 combinations show a positive raw edge, but only 1 of 10 — Natural Gas short, at p = 0.004 — is statistically distinguishable from chance, and that one significant result is worse than chance.
Cumulative signal PnL over the trade sequence for each instrument. Oil trends positive and Gold/Natural Gas trend negative over the full sample, though the per-cell significance test above is the more honest read than the raw curve shape.
Tests whether the signal's own confidence score (pivot-count asymmetry) predicts
accuracy. Pooled point-biserial correlation between confidence and hit: r = +0.042
— essentially zero. Hit rates across confidence terciles are statistically
indistinguishable (47–52%, heavily overlapping confidence intervals).
The original, more elaborate design (legacy_v1: bar-by-bar touch/break
classification, zero-break eligibility, a separate regime trim) run through the
identical backtest harness as the current simplified whisper-proximity rule (V3).
V1's looser eligibility fires 5–8x more often (639–1024 signals vs. 101–251 per cell),
giving lower-variance, near-zero edge estimates; V3's smaller sample lets both bigger
wins and bigger losses through. Neither version is a reliable edge source overall.
Applies each instrument's real recorded average spread (not an assumed constant) as a round-trip cost. Only 3 of 10 symbol/side combinations are net-profitable after cost, and none of those three were even nominally significant in the hit-rate test — the one statistically significant cell (Natural Gas short) is decisively unprofitable at −77.2 bps/trade.
A 5×5 grid of window (10–40h) × horizon (4–24h) swept across all 5 symbols and
both sides (250 cells). 11 of 200 sufficiently-sampled cells are nominally
significant at p < 0.05 — almost exactly the ~10 expected from testing 200 cells by
chance alone — and 0 survive Bonferroni correction. The one standout pattern,
Natural Gas short at window = 20h, is consistently negative across horizons 4/8/12/16,
which is what motivated testing the inverted (persistent-pressure) thesis below.
Splits signals by Kaufman's Efficiency Ratio (a standard trend/chop measure) into ranging/mixed/trending terciles, compared against each tertile's own conditional base rate rather than the unconditional market rate. No cell is significant at this sample size, but the direction is consistent with the signal's range-bound premise: hit rate declines from ranging toward trending on both sides.
The two mirror-image theses run through identical significance and cost analysis on the exact same fired events. This is where the project's one surviving result appears: Natural Gas, persistent-pressure, long — p = 0.004, net +23.4 bps/trade after real spread. Flagged in the source project as a narrow lead worth out-of-sample validation, not a proven edge (n = 101 signals, found after testing ~20 independent buckets plus 200 sweep cells).
All research, code, statistical methodology, and chart generation for both projects were authored by James Sawyer (github.com/jsawyerdev). This repository packages and documents the image output only; see the source projects for full implementations, tests, and methodology writeups.
Images and this writeup are shared for portfolio and educational reference. Nothing in this repository is investment advice — every backtest above is explicit that most tested signal/symbol combinations are statistically indistinguishable from chance or unprofitable after real trading costs.


















