OPEN-SOURCE SCRIPT
EMA 20/50 Optimal Distance (M15)

EMA 20/50 Optimal Distance (M15) is a quantitative context filter designed to evaluate market direction and trading conditions in XAUUSD using exponential moving averages.
This indicator uses the 20 EMA and 50 EMA on the 15-minute timeframe to define two key components:
1. Market bias (direction)
2. Risk level based on EMA separation
--- DIRECTION LOGIC ---
- BUY:
EMA 20 > EMA 50 and price is above both averages.
- SELL:
EMA 20 < EMA 50 and price is below both averages.
- NO BIAS:
When price is between EMAs or alignment is unclear.
--- EMA DISTANCE (NORMALIZED) ---
The distance is calculated as the absolute difference between EMA 20 and EMA 50, normalized for XAUUSD volatility.
Classification:
- High Risk:
Distance < 0.8
→ Weak or ranging market conditions.
- Medium Risk:
Distance between 0.8 and 1.5
→ Acceptable but not optimal conditions.
- Low Risk (Optimal):
Distance > 1.5
→ Strong trend with higher probability of continuation.
---
--- WHAT MAKES THIS INDICATOR DIFFERENT ---
Unlike standard EMA crossover tools, this script introduces a quantitative layer by measuring the distance between moving averages to classify market conditions.
It is not designed to generate entry signals, but to provide a structured and measurable framework for:
- Filtering trades based on market quality
- Categorizing setups by risk conditions
- Supporting data-driven decision making
---
--- PURPOSE ---
This indicator is specifically built as a base tool for backtesting and quantitative strategy development.
It is intended to be used in combination with market structure models (such as BOS/CHOCH) and lower timeframe execution strategies.
The goal is to help traders:
- Collect structured data
- Identify statistical edge
- Optimize entries, trade management, and sessions based on real performance metrics
---
Designed for intraday trading in Gold (XAUUSD).
EMA 20/50 – Distancia Óptima (M15) es un indicador diseñado para evaluar el contexto direccional y la calidad del entorno de mercado en XAUUSD mediante medias móviles exponenciales.
Utiliza la EMA 20 y EMA 50 en temporalidad de 15 minutos para definir el sesgo de mercado y el nivel de riesgo según la distancia entre ambas.
Este indicador no genera entradas, sino que funciona como filtro cuantitativo para backtesting y desarrollo de estrategias basadas en estructura de mercado (BOS/CHOCH).
Permite analizar condiciones de mercado, clasificar operaciones y optimizar decisiones en base a datos reales.
This indicator uses the 20 EMA and 50 EMA on the 15-minute timeframe to define two key components:
1. Market bias (direction)
2. Risk level based on EMA separation
--- DIRECTION LOGIC ---
- BUY:
EMA 20 > EMA 50 and price is above both averages.
- SELL:
EMA 20 < EMA 50 and price is below both averages.
- NO BIAS:
When price is between EMAs or alignment is unclear.
--- EMA DISTANCE (NORMALIZED) ---
The distance is calculated as the absolute difference between EMA 20 and EMA 50, normalized for XAUUSD volatility.
Classification:
- High Risk:
Distance < 0.8
→ Weak or ranging market conditions.
- Medium Risk:
Distance between 0.8 and 1.5
→ Acceptable but not optimal conditions.
- Low Risk (Optimal):
Distance > 1.5
→ Strong trend with higher probability of continuation.
---
--- WHAT MAKES THIS INDICATOR DIFFERENT ---
Unlike standard EMA crossover tools, this script introduces a quantitative layer by measuring the distance between moving averages to classify market conditions.
It is not designed to generate entry signals, but to provide a structured and measurable framework for:
- Filtering trades based on market quality
- Categorizing setups by risk conditions
- Supporting data-driven decision making
---
--- PURPOSE ---
This indicator is specifically built as a base tool for backtesting and quantitative strategy development.
It is intended to be used in combination with market structure models (such as BOS/CHOCH) and lower timeframe execution strategies.
The goal is to help traders:
- Collect structured data
- Identify statistical edge
- Optimize entries, trade management, and sessions based on real performance metrics
---
Designed for intraday trading in Gold (XAUUSD).
EMA 20/50 – Distancia Óptima (M15) es un indicador diseñado para evaluar el contexto direccional y la calidad del entorno de mercado en XAUUSD mediante medias móviles exponenciales.
Utiliza la EMA 20 y EMA 50 en temporalidad de 15 minutos para definir el sesgo de mercado y el nivel de riesgo según la distancia entre ambas.
Este indicador no genera entradas, sino que funciona como filtro cuantitativo para backtesting y desarrollo de estrategias basadas en estructura de mercado (BOS/CHOCH).
Permite analizar condiciones de mercado, clasificar operaciones y optimizar decisiones en base a datos reales.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。