OPEN-SOURCE SCRIPT
Variance Ratio & Efficiency Ratio (Quant Lab)

1️⃣ Variance Ratio (VR)
Formula:
VR ≈ Var(q-step returns) / (q × Var(1-step returns))
Interpretation:
• VR ≈ 1 → The market is like a random walk; neither trend nor mean-reversion is dominant.
• VR > 1 → Trend behavior is dominant.
• Trend-following systems (EMA, Supertrend, breakout) work better.
• VR < 1 → Mean-reversion is dominant.
• Range/reversal strategies (Z-score, Bollinger fade, RSI reversal) work better.
In short:
• VR > 1 → Trending market
• VR < 1 → Mean-reverting market
This tells you:
“Should I build a trend system or a mean-reversion system for this instrument?”
⸻
2️⃣ Efficiency Ratio (ER)
Formula logic:
ER = |Close_now – Close_n-bars-ago| / Σ|Close_i – Close_{i+1}|
In other words:
• Numerator → Net movement over N bars
• Denominator → Total noise over N bars
Interpretation:
• ER ≈ 1 → The price has moved in almost a straight line in one direction.
→ The trend is very efficient, noise is low.
• ER ≈ 0 → The price has fluctuated a lot but hasn't gone anywhere definitively.
→ A complete noise/range market.
This tells you:
“How clear is the trend in this last N bars, and how much noise is there?”
⸻
🔥 The intelligence provided by both together:
• VR > 1 and ER is high (0.6–1.0) →
➜ Strong, high-quality trend. Golden age for trend-following.
• VR > 1 but ER is low (0.2–0.4) →
➜ Trend exists but there is a lot of noise, many fake movements. • VR < 1 and ER is low →
➜ Net range / sideways market. Ideal for mean-reversion.
Formula:
VR ≈ Var(q-step returns) / (q × Var(1-step returns))
Interpretation:
• VR ≈ 1 → The market is like a random walk; neither trend nor mean-reversion is dominant.
• VR > 1 → Trend behavior is dominant.
• Trend-following systems (EMA, Supertrend, breakout) work better.
• VR < 1 → Mean-reversion is dominant.
• Range/reversal strategies (Z-score, Bollinger fade, RSI reversal) work better.
In short:
• VR > 1 → Trending market
• VR < 1 → Mean-reverting market
This tells you:
“Should I build a trend system or a mean-reversion system for this instrument?”
⸻
2️⃣ Efficiency Ratio (ER)
Formula logic:
ER = |Close_now – Close_n-bars-ago| / Σ|Close_i – Close_{i+1}|
In other words:
• Numerator → Net movement over N bars
• Denominator → Total noise over N bars
Interpretation:
• ER ≈ 1 → The price has moved in almost a straight line in one direction.
→ The trend is very efficient, noise is low.
• ER ≈ 0 → The price has fluctuated a lot but hasn't gone anywhere definitively.
→ A complete noise/range market.
This tells you:
“How clear is the trend in this last N bars, and how much noise is there?”
⸻
🔥 The intelligence provided by both together:
• VR > 1 and ER is high (0.6–1.0) →
➜ Strong, high-quality trend. Golden age for trend-following.
• VR > 1 but ER is low (0.2–0.4) →
➜ Trend exists but there is a lot of noise, many fake movements. • VR < 1 and ER is low →
➜ Net range / sideways market. Ideal for mean-reversion.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.