MACD Strategy Optimization for TradingView
Optimize MACD strategy parameters on TradingView with Pineify grid search. Test Fast MA, Slow MA, Signal line, and entry thresholds across thousands of combinations.
Add to Chrome FreeBuilding a MACD Strategy
The Moving Average Convergence Divergence (MACD) is a trend-following momentum indicator that shows the relationship between two exponential moving averages. The MACD line is calculated by subtracting the 26-period EMA from the 12-period EMA. A signal line (typically a 9-period EMA of the MACD line) generates buy and sell signals when crossovers occur.
The classic MACD strategy buys when the MACD line crosses above the signal line and sells when it crosses below. An entry threshold can filter out weak crossovers near the zero line. The four knobs you can tune are: Fast MA Length, Slow MA Length, Signal Line Length, and Entry Threshold. Small changes to any one of them can flip a losing strategy into a winner. I have seen strategies where bumping the Fast MA from 12 to 14 cut drawdown by half.
Optimizable Parameters
| Parameter | Description | Typical Range |
|---|---|---|
| Fast MA Length | The shorter EMA used to calculate the MACD line | 5 - 30 (step 1) |
| Slow MA Length | The longer EMA used to calculate the MACD line | 15 - 50 (step 1) |
| Signal Line Length | The EMA period applied to the MACD line to generate crossover signals | 5 - 20 (step 1) |
| Entry Threshold | Minimum distance from zero line to confirm crossover entry | 0 - 10 (step 1) |
Real Optimization Run
I ran a grid search on MACD with Fast MA 5-30 (step 1), Slow MA 15-50 (step 1), Signal Line 5-20 (step 1), and Entry Threshold 0-10 (step 1) across ETHUSD on the 4-hour chart. That is 26 x 36 x 16 x 11 = 164,736 combinations. The optimization completed in about 18 minutes. Best result used Fast MA 10, Slow MA 28, Signal Line 7, Entry Threshold 3 with a profit factor of 2.1 across 2 years. Not sure this works on every pair : I got very different results on BTCUSD where the Entry Threshold needed to be 6 or higher. Default MACD settings (12, 26, 9) produced decent results but the optimized set doubled the Sharpe ratio. Your mileage may vary, but that is exactly why you grid search.
Frequently Asked Questions
Related Strategy Optimizations
Start Optimizing Your MACD Strategy
Download Pineify Supercharged for free and run your first grid search optimization in minutes.
Add to Chrome Free