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が提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。