OPEN-SOURCE SCRIPT
Updated MACD Backtesting Indicator

This Pine Script v5 indicator replicates TradingView's standard MACD with full backtesting capabilities. Traders can adjust all parameters (12,26,9 defaults) through inputs and see real-time performance metrics in the table. Buy/sell signals appear as labeled arrows, matching classic MACD crossover strategy while providing visual backtest results for strategy evaluation.
Release Notes
EMA ImplementationEMA replaces SMA in MACD calculation using getMA() function that switches between ta.ema() and ta.sma() based on user input. Default is EMA for faster price response - standard TradingView MACD actually uses EMA internally.
Key Benefits of EMA over SMA:
Weights recent prices higher (exponential decay)
Faster trend detection and signal generation
Less lag in volatile markets
Traders select "EMA" (default) or "SMA" via dropdown. Table shows active MA type. EMA typically generates more signals due to quicker response.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.