ml_india is a dependency-free library for Pine v6 that packages the two pieces of context every India-market study should gate on but generic tools ignore: the India VIX regime and the NIFTY spot–futures basis. Import one shared implementation and “fear regime” and “premium / discount” mean the same thing across every script you build.

What it gives
VIX regime — where India VIX sits in its own recent range: fearful (risk-off), complacent, or normal.
VIX term-structure proxy — short-term vs longer-term implied vol, as a stand-in for the futures curve when that isn’t on your feed.
Spot–futures basis — the NIFTY futures premium/discount, raw and annualized, plus a self-calibrating regime.
riskState — the VIX regime and basis regime combined into a single risk-on / risk-off number.
Design — host-fed

The statistics are host-fed: you fetch India VIX (e.g. NSE:INDIAVIX) and NIFTY spot versus the futures you’re charting with request.security / input.source, and pass the series in. So the library carries no hard-wired tickers and works whatever your feed calls them. A fetch helper is included for convenience. Every read is a pure function of the series you pass — nothing repaints.

The functions
fetch(sym) — a symbol’s close on the chart timeframe. For wiring VIX / spot inputs.
vixRegime(vix, len, hiPct, loPct) — VIX percentile over len: +1 high fear (risk-off), −1 complacent, 0 normal.
vixTermProxy(vix, fastLen, slowLen) — (fast EMA − slow EMA) / slow EMA of the index: >0 backwardation (short-term stress building), <0 contango (calm). A single-series stand-in for a genuine VIX-futures curve.
basis(spot, fut) — (fut − spot) / spot. Positive = futures premium (carry / bullish lean); negative = discount / backwardation.
basisAnn(spot, fut, dte) — the basis annualized by days-to-expiry (× 365 / dte), so different expiries are comparable.
basisRegime(spot, fut, len, z) — the basis z-scored against its own history: +1 rich premium, −1 discount/backwardation, 0 normal. Self-calibrating to each symbol’s typical carry.
riskState(vix, spot, fut, len, hiPct, loPct, z) — one context read: +1 risk-ON (VIX complacent and futures at a premium), −1 risk-OFF (VIX fearful or basis in discount — either alone is enough to de-risk), 0 mixed.
How to use

See also  TASC 2026.09 Adaptive SuperSmoother — Indicator by PineCodersTASC — TradingView

Fetch the context and gate a signal by it:

//version=6
indicator(“Example — India context”, overlay = false)
import Market_Logic_India/ml_india/1 as ind

vix = ind.fetch(“NSE:INDIAVIX”)
spot = ind.fetch(“NSE:NIFTY”)
fut = close // the futures you are charting (e.g. NIFTY1!)

vReg = ind.vixRegime(vix, 100, 80, 20) // +1 fear / -1 calm / 0
bReg = ind.basisRegime(spot, fut, 100, 1.0) // +1 premium / -1 discount / 0
risk = ind.riskState(vix, spot, fut, 100, 80, 20, 1.0) // +1 risk-on / -1 risk-off / 0

bgcolor(risk < 0 ? color.new(color.red, 88) : risk > 0 ? color.new(color.green, 88) : na)
plot(ind.basisAnn(spot, fut, 7), “Annualized basis”)
Scope / honesty

NSE open-interest (OI-delta) is deliberately not here — Pine does not expose index-futures OI on retail feeds, so any “OI” read would be fabricated. The VIX and basis reads are the genuinely-available NIFTY-native context; pair them with your own OI source if you have one. India VIX itself is a 30-day model index, so vixTermProxy is a single-series proxy, not a true two-point curve — treat it as a fast “stress building” flag.

Concept credits

Volatility-index term structure (contango / backwardation) and the cost-of-carry spot–futures basis are standard derivatives concepts; India VIX is NSE’s volatility index. This library is an original, dependency-free Pine v6 packaging of those public techniques; it is not affiliated with, nor endorsed by, NSE or any originator.

License

Mozilla Public License 2.0 — as required for TradingView libraries (open source). Free to import and build on.

Library “ml_india”

fetch(sym)
  Parameters:
    sym (simple string)

vixRegime(vix, len, hiPct, loPct)
  Parameters:
    vix (float)
    len (simple int)
    hiPct (simple float)
    loPct (simple float)

vixTermProxy(vix, fastLen, slowLen)
  Parameters:
    vix (float)
    fastLen (simple int)
    slowLen (simple int)

See also  Equal Highs and Lows with Relative [CantoLab] — Indicator by CantoLab — TradingView

basis(spot, fut)
  Parameters:
    spot (float)
    fut (float)

basisAnn(spot, fut, dte)
  Parameters:
    spot (float)
    fut (float)
    dte (simple float)

basisRegime(spot, fut, len, z)
  Parameters:
    spot (float)
    fut (float)
    len (simple int)
    z (simple float)

riskState(vix, spot, fut, len, hiPct, loPct, z)
  Parameters:
    vix (float)
    spot (float)
    fut (float)
    len (simple int)
    hiPct (simple float)
    loPct (simple float)
    z (simple float)


Source link

Author

Shin John
Shin JohnYtv Market News
Share-market news writer and analyst with deep experience covering equities, commodities, forex, and cryptocurrencies for readers in the USA, UK, Canada, and Australia. Ytv Market News delivers timely market updates, practical trading insights, and clear explanations of macro and company-level catalysts that move prices. Combines on-the-ground financial reporting with technical analysis, using concise charts and actionable ideas to help investors and traders make smarter decisions.