OPEN-SOURCE SCRIPT
Two Sigma Factor Composite [JOAT]

TWO SIGMA FACTOR COMPOSITE [JOAT]
A tribute to the multi-factor approach pioneered by Two Sigma — long-only, long/short, and risk-premia funds that decompose returns into orthogonal factor exposures, normalise each factor onto the same statistical scale, and combine them into a single signed score. Two Sigma Factor Composite builds five canonical factors (Momentum, Quality, Value, Volatility, Mean-Reversion), Z-normalises each against a rolling baseline, sum-normalises the user-controllable weights, and outputs a composite score with signal labels, factor sparklines on the chart, and a rolling hit-rate backtest.

The five factors
Each factor is computed independently and Z-normalised over a configurable window (default 100 bars) with optional outlier clipping (default ±4σ):
Each factor's window is independently configurable. All five outputs are Z-scores capped at ±4σ to prevent any single outlier from dominating the composite.
Sum-normalised weights
Five weight sliders (default 1.0 each) are normalised internally so any positive combination is valid. Default equal weight is the most defensible baseline; tune individual weights to bias the composite. Want a pure momentum + quality read? Set the others to 0.1 and Momentum/Quality to 2.0. The composite reshapes itself live.
Signal engine — bounded composite with three tiers
The composite is bounded by the clipping cap. The signal engine layers three thresholds:
A configurable signal cooldown (default 10 bars) prevents clustering.
Factor sparklines (the signature visual)
The script renders inline sparklines on the chart for all five factors — small line plots that visually show each factor's recent Z trajectory. Configurable base offset (vertical position below zero), row spacing, amplitude, and per-row transparency mapping. At a glance you see which factors are driving the composite and which are flat.
When all five sparklines lean the same way, the composite is high-confidence. When they disagree, the composite is a weighted compromise — the sparklines tell you the truth that a single number cannot.

Visual system
A locked Emerald Night palette: vivid green bull / vivid red bear / sage mid on a deep emerald background — strict 2-hue discipline with bg. No third colour invented anywhere; all variations are transparency-only.
Dashboard
Monospaced table positionable to any of eight corners. Surfaces:
Alerts
Five alert conditions, each independently controllable:
How to read it
Three reads, in order of conviction:
Suggested settings
Defaults (momentum 50 / quality vol 50 / value 200 / vol 20/252 / MR 20, Z window 100, ±4σ clip, ±1.0 buy/sell, ±2.0 extreme, 10-bar cooldown) are tuned for daily charts on broad indices — the timeframes where factor approaches are statistically meaningful. For lower timeframes drop all windows proportionally. For weekly+ keep defaults; factor reads on weekly are the canonical institutional horizons.
Originality / what's reused
The factor-investing framework is published academic finance — Fama-French 1992, Carhart 1997, AQR 2013, and many others. The five factors used here (Momentum, Quality, Value, Volatility, Mean-Reversion) are the canonical institutional factor set. The implementation here — the five-factor pipeline with each factor's window independently configurable, the rolling Z-normalisation with outlier clipping, the sum-normalised five-weight composition, the bounded-composite signal engine with three-tier thresholds, the inline factor sparklines render in the same pane, the rolling forward-bar hit-rate backtest, and the strict 2-hue alpha-only palette — is JOAT-original. No third-party code reused. The script is a tribute to Two Sigma-style factor-composite portfolio construction, not a direct replication of any proprietary Two Sigma model.
Limitations
The five factors are computed from chart data only — they are time-series proxies of the cross-sectional factors used in true multi-asset portfolios. The Z-normalisation needs the window populated; early bars give a warm-up read. The forward-N-bar hit-rate backtest is descriptive of recent signal behaviour under the current settings; it is not a predictive metric. Factor exposures historically underperform for extended periods — the dashboard's agreement row and the low-agreement alert exist specifically to warn you when the model is breaking down.
—
-made with passion by jackofalltrades
A tribute to the multi-factor approach pioneered by Two Sigma — long-only, long/short, and risk-premia funds that decompose returns into orthogonal factor exposures, normalise each factor onto the same statistical scale, and combine them into a single signed score. Two Sigma Factor Composite builds five canonical factors (Momentum, Quality, Value, Volatility, Mean-Reversion), Z-normalises each against a rolling baseline, sum-normalises the user-controllable weights, and outputs a composite score with signal labels, factor sparklines on the chart, and a rolling hit-rate backtest.
The five factors
Each factor is computed independently and Z-normalised over a configurable window (default 100 bars) with optional outlier clipping (default ±4σ):
- Momentum — return / volatility over the configurable momentum window (default 50 bars). The classic "trend" factor.
- Quality — inverse of recent realised volatility (default 50-bar window). Lower volatility = higher quality; an asset that has been calmer is treated as higher quality, consistent with academic factor research.
- Value — deviation from a long mean (default 200-bar SMA). Negative deviation = "cheap" (positive value factor exposure); positive deviation = "expensive". The classical cross-sectional value definition, adapted to time series.
- Volatility — percentile rank of recent realised volatility (default 20-bar stdev percentile-ranked over 252 bars). High vol = negative factor; low vol = positive factor.
- Mean-Reversion — signed deviation from a 20-bar mean (default). Captures short-term reversion bias.
Each factor's window is independently configurable. All five outputs are Z-scores capped at ±4σ to prevent any single outlier from dominating the composite.
Sum-normalised weights
Five weight sliders (default 1.0 each) are normalised internally so any positive combination is valid. Default equal weight is the most defensible baseline; tune individual weights to bias the composite. Want a pure momentum + quality read? Set the others to 0.1 and Momentum/Quality to 2.0. The composite reshapes itself live.
Signal engine — bounded composite with three tiers
The composite is bounded by the clipping cap. The signal engine layers three thresholds:
- Buy — composite crosses above the buy threshold (default +1.0σ).
- Sell — composite crosses below the sell threshold (default −1.0σ).
- Extreme Bull / Extreme Bear — |composite| crosses ±2.0σ. The script's strongest read.
A configurable signal cooldown (default 10 bars) prevents clustering.
Factor sparklines (the signature visual)
The script renders inline sparklines on the chart for all five factors — small line plots that visually show each factor's recent Z trajectory. Configurable base offset (vertical position below zero), row spacing, amplitude, and per-row transparency mapping. At a glance you see which factors are driving the composite and which are flat.
When all five sparklines lean the same way, the composite is high-confidence. When they disagree, the composite is a weighted compromise — the sparklines tell you the truth that a single number cannot.
Visual system
- Composite line (configurable width, default 3px) with sign-coloured fill toward zero (configurable transparency).
- Threshold lines at ±buyTH and ±extremeTH (configurable transparency).
- Buy / Sell labels on chart on threshold crosses.
- Factor sparklines — five inline Z-trajectory plots in the pane.
- Optional chart-background override to follow chart.bg_color.
A locked Emerald Night palette: vivid green bull / vivid red bear / sage mid on a deep emerald background — strict 2-hue discipline with bg. No third colour invented anywhere; all variations are transparency-only.
Dashboard
Monospaced table positionable to any of eight corners. Surfaces:
- Composite Z value and sign.
- Per-factor Z rows (Momentum / Quality / Value / Volatility / Mean-Reversion).
- Factor agreement percentage (how many factors agree with composite sign).
- Last signal direction with bars-ago.
- Weight configuration in use.
- Backtest stats row — rolling forward-N-bar hit rate (configurable lookahead, default 10 bars). The script's own performance audit.
Alerts
Five alert conditions, each independently controllable:
- BUY Cross (composite crosses above buy threshold)
- SELL Cross
- Extreme Bull (composite > +2.0σ)
- Extreme Bear (composite < −2.0σ)
- Low Factor Agreement (% of factors agreeing falls below the configurable threshold, default 40%) — the script's "no edge" warning.
How to read it
Three reads, in order of conviction:
- Extreme score with high factor agreement (e.g. composite > +2.0σ AND agreement > 80%) — the highest-conviction read the script produces. Four or five factors are pointing decisively one way, and the composite is at a statistical extreme.
- Buy / Sell with sparkline confirmation — visual confirmation that the directional read is being driven by multiple factors, not just one. If the composite is bullish but only the Momentum sparkline is leaning, the read is fragile; if Momentum + Quality + Value + Mean-Reversion all lean, the read is robust.
- Low Agreement alert — stand-aside signal. The factors disagree internally; the composite is a wash. Wait for re-alignment.
Suggested settings
Defaults (momentum 50 / quality vol 50 / value 200 / vol 20/252 / MR 20, Z window 100, ±4σ clip, ±1.0 buy/sell, ±2.0 extreme, 10-bar cooldown) are tuned for daily charts on broad indices — the timeframes where factor approaches are statistically meaningful. For lower timeframes drop all windows proportionally. For weekly+ keep defaults; factor reads on weekly are the canonical institutional horizons.
Originality / what's reused
The factor-investing framework is published academic finance — Fama-French 1992, Carhart 1997, AQR 2013, and many others. The five factors used here (Momentum, Quality, Value, Volatility, Mean-Reversion) are the canonical institutional factor set. The implementation here — the five-factor pipeline with each factor's window independently configurable, the rolling Z-normalisation with outlier clipping, the sum-normalised five-weight composition, the bounded-composite signal engine with three-tier thresholds, the inline factor sparklines render in the same pane, the rolling forward-bar hit-rate backtest, and the strict 2-hue alpha-only palette — is JOAT-original. No third-party code reused. The script is a tribute to Two Sigma-style factor-composite portfolio construction, not a direct replication of any proprietary Two Sigma model.
Limitations
The five factors are computed from chart data only — they are time-series proxies of the cross-sectional factors used in true multi-asset portfolios. The Z-normalisation needs the window populated; early bars give a warm-up read. The forward-N-bar hit-rate backtest is descriptive of recent signal behaviour under the current settings; it is not a predictive metric. Factor exposures historically underperform for extended periods — the dashboard's agreement row and the low-agreement alert exist specifically to warn you when the model is breaking down.
—
-made with passion by jackofalltrades
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
The AI Trading Ecosystem, Built to win trades 📈
Get Full Access 👇
jackofalltrades.vip 🌐
t.me/jackofalltradesvip 🃏
Get Full Access 👇
jackofalltrades.vip 🌐
t.me/jackofalltradesvip 🃏
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
The AI Trading Ecosystem, Built to win trades 📈
Get Full Access 👇
jackofalltrades.vip 🌐
t.me/jackofalltradesvip 🃏
Get Full Access 👇
jackofalltrades.vip 🌐
t.me/jackofalltradesvip 🃏
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.