OPEN-SOURCE SCRIPT
Best EMA Finder

This script, Best EMA Finder, is based on the same original logic as the Best SMA Finder I published previously. Although it was not the initial goal of the project, several users asked for an EMA version, so here it is.
The script scans a wide range of Exponential Moving Average (EMA) lengths, from 10 to 500, and identifies the one that historically delivered the most robust performance on the current chart. The choice to stop at 500 is deliberate: beyond that point, EMA curves tend to flatten and converge, adding processing time without meaningful differences in signals or outcomes.
Each EMA is evaluated using a custom robustness score:
Profit Factor × log(Number of Trades) × sqrt(Win Rate)
Only EMA lengths that exceed a user-defined minimum number of trades are considered valid. Among these, the one with the highest robustness score is selected and displayed on the chart.
A table summarizes the results:
- Best EMA length
- Total number of trades
- Profit Factor
- Win Rate
- Robustness Score
You can adjust:
- Strategy type: Long Only or Buy & Sell
- Minimum number of trades required
- Table visibility
This script is designed for analysis and optimization only. It does not execute trades or handle position sizing. Only one open trade per direction is considered at a time.
The script scans a wide range of Exponential Moving Average (EMA) lengths, from 10 to 500, and identifies the one that historically delivered the most robust performance on the current chart. The choice to stop at 500 is deliberate: beyond that point, EMA curves tend to flatten and converge, adding processing time without meaningful differences in signals or outcomes.
Each EMA is evaluated using a custom robustness score:
Profit Factor × log(Number of Trades) × sqrt(Win Rate)
Only EMA lengths that exceed a user-defined minimum number of trades are considered valid. Among these, the one with the highest robustness score is selected and displayed on the chart.
A table summarizes the results:
- Best EMA length
- Total number of trades
- Profit Factor
- Win Rate
- Robustness Score
You can adjust:
- Strategy type: Long Only or Buy & Sell
- Minimum number of trades required
- Table visibility
This script is designed for analysis and optimization only. It does not execute trades or handle position sizing. Only one open trade per direction is considered at a time.
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
The trend is your friend, until it's not...
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
The trend is your friend, until it's not...
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。