OPEN-SOURCE SCRIPT

MARKET OS [Viprasol]

963
MARKET OS [Viprasol] — Cost-Aware Regime & Signal Engine

═══════════════════════════════════════════════════════════
THE IDEA IN ONE LINE
═══════════════════════════════════════════════════════════

Most indicators read one thing — trend, volume, or structure — and leave you
to guess the rest. MARKET OS reads the market across four independent
dimensions at once, fuses them into a single 0-100 Market Score, and grades
every signal A/B/C — including something no other signal engine on
TradingView shows: the estimated ROUND-TRIP TRADING COST of taking that
signal, stamped right on the label.

═══════════════════════════════════════════════════════════
THE FOUR DIMENSIONS
═══════════════════════════════════════════════════════════

1. DIRECTION — adaptive trend + market structure
A Kaufman Adaptive Moving Average (KAMA) baseline that hugs price in
trends and slows down in chop, combined with swing structure tracking
(BOS continuation counts and CHoCH reversals with a configurable
confirmation requirement). Direction scores highest when adaptive trend
and structure AGREE.

2. QUALITY — efficiency regime
The Kaufman Efficiency Ratio (0 = pure chop, 1 = perfect one-way move)
classifies the environment as TRENDING / TRANSITION / CHOPPY. A breakout
in a trending regime and the same breakout in chop are not the same trade
— this dimension prices that difference into the score.

3. PARTICIPATION — effort vs result (Wyckoff)
Relative volume (EFFORT) is compared against ATR-normalized price movement
(RESULT) on every bar:
• High effort + high result = CONVICTION (real participation)
• High effort + low result = ABSORPTION (volume swallowed — warning
crosses on the chart; a classic exhaustion footprint)
• Low effort + high result = THIN MOVE (prone to fade)

4. COST — EDGE effective spread (the genuinely new part)
The engine embeds the EDGE estimator from Ardia, Guidotti & Kroencke,
"Efficient Estimation of Bid-Ask Spreads from Open, High, Low, and Close
Prices", Journal of Financial Economics 161 (2024) — an asymptotically
unbiased estimator of the effective bid-ask spread computed from nothing
but OHLC bars. The current spread is ranked against the symbol's own
history, so the engine knows when this market is CHEAP or EXPENSIVE to
trade. To my knowledge this is the first TradingView signal engine that
measures its own trading cost.

═══════════════════════════════════════════════════════════
THE FUSION: MARKET SCORE & STATE
═══════════════════════════════════════════════════════════

The four dimensions are combined into a weighted composite score
(Direction 30%, Quality 30%, Participation 25%, Cost 15%):

75-100 ◆ PRIME — everything aligned, cheap to trade
55-74 ◆ FAVORABLE — good conditions
35-54 ◆ MIXED — partial alignment
0-34 ◆ HOSTILE — choppy / absorbed / expensive (background shaded)

Candles are colored on a continuous gradient from neutral gray to full trend
color as the score rises — you can see environment quality at a glance,
without reading a single number.

═══════════════════════════════════════════════════════════
SIGNALS — GRADED AND COST-STAMPED
═══════════════════════════════════════════════════════════

Entries are structure reversals (CHoCH) confirmed by the adaptive trend,
gated by a minimum score, and stamped with:

▲ LONG [A]
Score 82
Cost 4.2t / Tgt 38t (11.1%)

That last line is the engine's cost-awareness: estimated round-trip spread
cost in ticks, your ATR-based target in ticks, and the percentage of your
target the spread will consume. If the cost eats 25%+ of the target, an
alert can tell you the trade is structurally overpriced — BEFORE you take it.

C-grade signals (reversal fired, but the environment scored poorly) are
hidden by default. They look like signals and trade like donations.

═══════════════════════════════════════════════════════════
HOW TO USE
═══════════════════════════════════════════════════════════

1. Pick a Preset: Fast (1-15m), Default (15m-1H), Smooth (1H+).
2. Trade A-grade signals in PRIME/FAVORABLE states, in the signal direction.
3. Treat ABSORPTION crosses as early reversal warnings.
4. Check the Round-Trip Cost row before entering — if the spread eats a
large slice of your target, size down, widen the target, or skip.
5. Use HOSTILE shading as a stand-aside filter.
6. Raise "Minimum Score to Signal" for fewer, cleaner entries.

═══════════════════════════════════════════════════════════
SETTINGS
═══════════════════════════════════════════════════════════

Engine — preset, KAMA length, structure pivot width.
Quality — ER smoothing and trending/choppy thresholds.
Participation — effort and result thresholds.
Cost — EDGE window, cost-regime lookback, target size in ATR multiples.
Signals — minimum score, C-grade visibility, BOS-before-flip, cooldown.
Visuals — colors, adaptive cloud, structure levels, gradient candles,
hostile shading, absorption markers.
Dashboard — position and size.

Alerts (8): Long, Short, A-Grade Signal, Prime State, Hostile State,
Absorption, High Cost Regime, Cost Eats Edge (≥25% of target).

═══════════════════════════════════════════════════════════
HONEST LIMITATIONS
═══════════════════════════════════════════════════════════

• The EDGE estimator is asymptotic — short windows are noisy, and on very
illiquid symbols or synthetic OHLC feeds (some forex/CFD data) the cost
dimension degrades; the engine then treats cost as neutral rather than
fabricating a number.
• Volume-based participation requires reliable volume data.
• Structure detection depends on pivot settings and timeframe.
• The score weights encode a judgment (direction and quality matter most);
they are not optimized parameters and you should not treat the score as a
probability.
• This is an analytical decision-support tool, not a trading system. Past
performance does not guarantee future results. Not financial advice.

═══════════════════════════════════════════════════════════
CREDITS & ORIGINALITY
═══════════════════════════════════════════════════════════

The EDGE estimator methodology belongs to David Ardia, Emanuele Guidotti and
Tim A. Kroencke (Journal of Financial Economics 161, 2024, 103916,
doi 10.1016/j.jfineco.2024.103916). KAMA and the Efficiency Ratio are Perry
Kaufman's public concepts; Effort-vs-Result is a Wyckoff principle. All code
in this script — the Pine implementation of EDGE from the published formulas,
the four-dimension fusion model, the composite scoring and state machine, the
cost-stamped signal engine, and all visualization — is original Viprasol work
written from scratch for this indicator. No third-party Pine code is reused.

Declinazione di responsabilità

Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.