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.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.