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.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.