OPEN-SOURCE SCRIPT
Aggiornato

Volatility Index Percentile Risk STOCK Strategy

249
Volatility-Index Percentile Risk STOCK Strategy
──────────────────────────────────────────────
PURPOSE
• Go long equities only when implied volatility (from any VIX-style index) is in its quietest percentile band.
• Scale stop-loss distance automatically with live volatility so risk stays proportional across timeframes and market regimes.

HOW IT WORKS
1. Pull the closing price of a user-selected volatility index (default: CBOE VIX, Nasdaq VXN, etc.).
2. Compute its 1-year (252-bar) percentile.
– If percentile < “Enter” threshold → open / maintain long.
– If percentile > “Exit” threshold → flatten.
3. Set the stop-loss every bar at:
SL % = (current VIX value) ÷ Risk Divisor
(e.g., VIX = 20 and divisor = 57 → 0.35 % SL below entry).
This keeps risk tighter when volatility is high and looser when it’s calm.

USER INPUTS
• VIX-style Index   — symbol of any volatility index
• Look-back     — length for percentile (default 252)
• Enter Long < Percentile — calm-market trigger (default 15 %)
• Exit Long > Percentile — fear trigger (default 60 %)
• Risk Divisor (SL)  — higher number = tighter stop; start with 57 on 30-min charts
• Show Debug Plots — optional visibility of percentile & SL%

RECOMMENDED BACK-TEST SETTINGS
• Timeframe: 30 min – Daily on liquid stocks/ETFs highly correlated to the chosen VIX.
• Initial capital: 100 000 | Order size: 10 % of equity
• Commission: 0.03 %   | Slippage: 5 ticks
• Enable *Bar Magnifier* and *Fill on bar close* for realistic execution.


ADDITIONAL INFORMATION
• **Self-calibrating risk** – no static ATR or fixed %, adapts instantly to changing volatility.
• **Percentile filter** – regime-aware entry logic that avoids false calm periods signalled by raw VIX levels.
• **Timeframe-agnostic** – works from intraday to weekly; √T-style divisor lets you fine-tune stops quickly ,together with the percentiles and days length.
• Zero look-ahead.

CAVEATS
• Long-only; no built-in profit target. Add one if your plan requires fixed R:R exits.
• Works best on indices/stocks that move with the selected vol index.
• Back-test results are educational; past performance never guarantees future returns.


LICENSE & CREDITS
Released under the Mozilla Public License 2.0.
Inspired by academic research on volatility risk premia and mean-reversion.

DISCLAIMER
This script is for informational and educational purposes only. It is **not** financial advice. Use at your own risk.
Note di rilascio
updated default settings

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.