OPEN-SOURCE SCRIPT

[SW Lab] Edge Analyzer

284
## What It Does

Most indicators tell you to buy or sell without evidence. The Edge Analyzer changes that by building a real-time statistical profile for every trading setup it detects -- showing you exactly how that setup has performed historically on this specific asset, timeframe, and market regime. When a setup triggers, you see hard numbers: win rate, profit factor, best and worst outcomes, and a Kelly-derived position size -- not opinions.

## How It Works

- Monitors four setup types simultaneously: RSI Oversold/Overbought, MA Crossover, Breakout (with volume confirmation), and Mean Reversion (Z-score based)
- Each time a setup triggers, the indicator records the bar, price, direction, and current market regime, then measures the forward return after a configurable evaluation window (default: 10 bars)
- Classifies the market into three regimes (Trending, Ranging, Volatile) using ATR ratio analysis and trend slope, allowing you to see whether a setup that works in one regime also works in another
- Computes both all-time and regime-filtered statistics, with automatic fallback to all-regime stats when the current regime has fewer than 5 samples
- Calculates Quarter-Kelly position sizing from the real win rate and reward-to-risk ratio, capped at 25% for safety

## Key Features

- **Four parallel setup detectors** running simultaneously with independent statistics
- **Stat card overlay** showing occurrences, win rate, average return, best/worst, profit factor, and Kelly sizing
- **Regime-conditional analysis** breaking performance into Trending, Ranging, and Volatile environments
- **Confidence rating**: HIGH (15+ regime samples), MEDIUM (5-14), or LOW (fewer than 5)
- **Best setup highlight**: when multiple setups fire on the same bar, the highest win rate setup is prioritized
- Signal arrows plotted directly on the chart for visual reference

## Signal Interpretation

| Stat Card Field | Meaning |
|----------------|---------|
| Win Rate (All) | Historical win percentage across all regimes |
| Win Rate (Regime) | Win percentage filtered to the current market regime only |
| Profit Factor | Total wins divided by total losses -- above 1.0 means net positive |
| Quarter Kelly | Suggested position size as a percentage of account, based on Kelly Criterion at 25% safety factor |
| Confidence | HIGH / MEDIUM / LOW based on regime-specific sample count |
| NO EDGE | Negative Kelly value -- setup has negative expected value |

## Settings Guide

| Parameter | Default | Description |
|-----------|---------|-------------|
| RSI Length | 14 | RSI calculation period |
| RSI OB/OS | 70 / 30 | Overbought and oversold thresholds |
| MA Fast / Slow | 20 / 50 | Moving average crossover periods |
| Breakout Length | 20 | N-bar high/low lookback |
| Volume Confirm Mult | 1.2 | Volume must exceed SMA(20) times this value |
| Z-Score Length | 20 | Mean reversion lookback period |
| Z-Score Threshold | 2.0 | Standard deviations from mean to trigger |
| Eval Bars | 10 | Forward bars to measure each signal outcome |
| Min Signals | 10 | Minimum signals before displaying statistics |
| ATR Fast / Slow | 14 / 50 | ATR periods for regime classification |
| Trend Length | 50 | SMA period for trend slope calculation |

## Alerts

- RSI setup triggered
- MA crossover setup triggered
- Breakout setup triggered
- Mean reversion setup triggered
- Any setup triggered (composite)

## Best Used For

- Validating whether a setup actually has an edge on your chosen asset and timeframe before risking capital
- Identifying which market regime favors which setup type
- Data-driven position sizing instead of arbitrary fixed-percentage risk
- Screening multiple assets to find where specific setups consistently perform
- Building conviction (or losing it) with real forward-return statistics

## Academic Foundation

Position sizing is based on the Kelly Criterion (Kelly, 1956), which maximizes the long-term geometric growth rate of a portfolio. The indicator uses Quarter Kelly (25% of full Kelly) to reduce variance, a widely adopted practice in professional trading.

## Disclaimer

This indicator is an analytical tool, not financial advice. Past statistical performance does not guarantee future results. Always apply your own risk management.

Exención de responsabilidad

La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.