By Sharma Research
Concept inspired by Tushar Chandeβs VIDYA
VIDYA MA 2.0 is an advanced adaptive moving average indicator designed to automatically adjust its speed based on market trend strength.
Traditional moving averages like SMA and EMA have fixed behavior:
-
EMA reacts fast but becomes noisy in sideways markets
-
SMA is smooth but reacts late in strong trends
VIDYA MA 2.0 addresses this by dynamically changing its smoothing based on trend strength, aiming to be responsive during trends and smoother during consolidations.
π How VIDYA MA 2.0 Works
The indicator continuously measures trend strength and adjusts how much importance it gives to price:
-
Strong trend β more weight to current price β faster reaction
-
Weak / sideways trend β more weight to past prices β smoother behavior
This creates a Variable Moving Average (VarMA) that adapts automatically to market conditions.
π§ Core Logic Explained (Simple)
-
Trend strength is calculated using a Wilder-style DI / ADX method
-
ADX values are normalized over a short lookback window
-
This normalized value acts as an adaptive constant
-
That constant controls how fast or slow the moving average responds
π Result: A moving average that adjusts dynamically to price behavior, instead of staying fixed.
βοΈ Dual-Line Structure
VIDYA MA 2.0 plots two adaptive lines using the same VarMA core:
-
Fast Line β Reflects short-term momentum
-
Slow Line β Indicates broader trend direction
Visual Fill:
-
π’ Green fill β Indicates potential bullish trend strength
-
π΄ Red fill β Indicates possible weakness or bearish bias
This is intended to help users visually interpret market conditions, without needing multiple indicators.
π¨ Momentum Crossovers (For Educational Use Only)
The crossover logic included in the script is intended solely for learning and backtesting:
-
Fast crosses above Slow β Momentum turning bullish
-
Fast crosses below Slow β Momentum turning bearish
β οΈ These are not trading signals or recommendations.
π§Ύ VIDYA MA 2.0 β Pine Script Code (TradingView)
π Copy the code below and paste it into TradingView β Pine Editor β Save & Add to Chart
//@version=5
// Vidya MA 2.0 by SharmaResearch.com
// Concept credit: Tushar Chande (VIDYA / Variable Index Dynamic Average)
//
// How this works (quick intro):
// This indicator builds an adaptive moving average (VarMA) whose smoothing changes with trend strength.
// It estimates trend strength using a Wilder-style DI/ADX calculation, normalizes that ADX over a short window,
// and uses the normalized value as an adaptive constant. When trend strength rises, the average adapts faster;
// when trend strength falls, it smooths more. Two SMAs of this adaptive VarMA (fast + slow) create a
// confirmed-close, dual-line system with a colored fill and optional crossover alerts.
indicator(title="Vidya MA 2.0 by SharmaResearch.com (Concept: Tushar Chande) β 2x Adaptive MA, Confirmed Close",
shorttitle="VidyaMA2.0",
overlay=true,
max_bars_back=5000)
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Minimal Inputs
adxLen = input.int(2, minval=1, title="ADX Length (for normalization)")
weighting = input.float(10, minval=1, title="Weighting (Wilder-like smoothing)")
fastLen = input.int(9, minval=1, title="Fast Length")
slowLen = input.int(20, minval=1, title="Slow Length")
src = input.source(close, "Source")
// Fixed styling (no inputs)
FAST_WIDTH = 4
SLOW_WIDTH = 2
FILL_TRANSP = 85
confirmed = barstate.isconfirmed // update/plot only on bar close in realtime
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Helpers
clamp(float x, float lo, float hi) =>
math.max(lo, math.min(hi, x))
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Adaptive VarMA Core (VIDYA-like behavior) β state updates ONLY on confirmed closes
var float sPDI = 0.0
var float sMDI = 0.0
var float STR = na
var float ADX = 0.0
var float VarMA = na
hi = high
lo = low
hi1 = nz(high[1], high)
lo1 = nz(low[1], low)
c1 = nz(close[1], close)
bulls1 = 0.5 * (math.abs(hi - hi1) + (hi - hi1))
bears1 = 0.5 * (math.abs(lo1 - lo) + (lo1 - lo))
bears = bulls1 > bears1 ? 0.0 : bulls1 == bears1 ? 0.0 : bears1
bulls = bulls1 < bears1 ? 0.0 : bulls1 == bears1 ? 0.0 : bulls1
// Correct True Range
tr = math.max(hi - lo, math.max(math.abs(hi - c1), math.abs(lo - c1)))
if confirmed
sPDI := (weighting * nz(sPDI[1], 0.0) + bulls) / (weighting + 1.0)
sMDI := (weighting * nz(sMDI[1], 0.0) + bears) / (weighting + 1.0)
STR := (weighting * nz(STR[1], (hi - lo)) + tr) / (weighting + 1.0)
pdi = STR > 0 ? (sPDI / STR) : 0.0
mdi = STR > 0 ? (sMDI / STR) : 0.0
dx = (pdi + mdi) > 0 ? (math.abs(pdi - mdi) / (pdi + mdi)) : 0.0
ADX := (weighting * nz(ADX[1], 0.0) + dx) / (weighting + 1.0)
VarMA := nz(VarMA[1], src)
else
// Hold last confirmed values intrabar
sPDI := nz(sPDI[1], 0.0)
sMDI := nz(sMDI[1], 0.0)
STR := nz(STR[1], (hi - lo))
ADX := nz(ADX[1], 0.0)
VarMA := nz(VarMA[1], src)
// Normalize ADX every bar (no scope warnings)
adxLow = ta.lowest(ADX, adxLen)
adxHigh = ta.highest(ADX, adxLen)
diff = adxHigh - adxLow
constRaw = diff > 0 ? ((ADX - adxLow) / diff) : 0.0
Const = clamp(constRaw, 0.0, 1.0)
// Update VarMA only on confirmed close
if confirmed
VarMA := ((2.0 - Const) * nz(VarMA[1], src) + Const * src) / 2.0
else
VarMA := nz(VarMA[1], src)
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Two adaptive MAs from the same VarMA (fast + slow)
fastRaw = ta.sma(VarMA, fastLen)
slowRaw = ta.sma(VarMA, slowLen)
// Hold plotted values intrabar (confirmed-close plotting)
var float vidyaFast = na
var float vidyaSlow = na
vidyaFast := confirmed ? fastRaw : nz(vidyaFast[1], fastRaw)
vidyaSlow := confirmed ? slowRaw : nz(vidyaSlow[1], slowRaw)
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Plots
fastColor = vidyaFast > vidyaFast[1] ? color.lime : color.red
slowColor = color.gray
pFast = plot(vidyaFast, title="Vidya MA Fast (Primary)", color=fastColor, linewidth=FAST_WIDTH)
pSlow = plot(vidyaSlow, title="Vidya MA Slow", color=slowColor, linewidth=SLOW_WIDTH)
// Fill between primary (fast) and slow
fillColor = vidyaFast >= vidyaSlow ? color.new(color.lime, FILL_TRANSP) : color.new(color.red, FILL_TRANSP)
fill(pFast, pSlow, color=fillColor, title="FastβSlow Fill")
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// Optional alerts: crossover on confirmed close (no extra inputs)
bullCross = confirmed and ta.crossover(vidyaFast, vidyaSlow)
bearCross = confirmed and ta.crossunder(vidyaFast, vidyaSlow)
alertcondition(bullCross, title="Bull Cross (Confirmed)", message="Vidya MA Fast crossed ABOVE Vidya MA Slow on {{ticker}} @ {{close}}")
alertcondition(bearCross, title="Bear Cross (Confirmed)", message="Vidya MA Fast crossed BELOW Vidya MA Slow on {{ticker}} @ {{close}}")
π Concept Inspiration
The original VIDYA (Variable Index Dynamic Average) was developed by Tushar Chande, a quantitative analyst and author.
VIDYA MA 2.0 is a modern interpretation of this concept, adding:
-
ADX normalization
-
Dual adaptive lines
-
Cleaner visual representation
π¨βπ» Developed By
Created and customized by Sharma Research
Written in Pine Script v5 for TradingView
Released for educational and research purposes only
π Important Disclosures
π’ Disclaimer: This is for informational purposes only. Nothing herein constitutes a buy or sell recommendation. I may or may not be holding a position in the stock mentioned.
π§βπΌ Rajneesh Sharma is a SEBI-registered Research Analyst (Reg. No. INH000020332).
π Investments are subject to market risks. Read all related documents carefully before investing.
π© Investor Charter & SCORES grievance redressal info is available on our blog.
