Trading Idea #015 – TASC Optimized MACD

This trading system idea comes to us by way of Technical Analysis of Stocks & Commodities (TASC) magazine’s website,  This is the third and final system idea from the systems that TASC features on their website.  This system uses MACD (Moving Average Convergence/Divergence), which is a trend-following momentum indicator.  This indicator was developed by Gerald Appel in the 1970’s and has proven to be very popular with traders. It is used to show changes in momentum, trend direction, and strength of a trend.

The rules TASC provides are straightforward: 

Buy signals are generated when the Moving Average Convergence Divergence line is below zero and crosses above the signal line. When the MACD line is above zero and crosses below the signal line, a sell signal is generated. Tested on daily price data. (source)

 I interpret these rules to be as follows:

  • Buy/reverse when the MACD is below zero and crosses over the smoothed MACD (signal line)
  • Sell short/reverse when the MACD is above zero and crosses under the smoothed MACD (signal line)

There are three optimized parameters: Fast Moving Average, Slow Moving Average, and Smoothing Constant. 

The first two TASC systems I tried, the Optimized Moving Average and Optimized CCI both bombed.  Having built Moving Average Convergence Divergence systems, I have little faith that this idea will work because they all failed.  My goal here is to see if their idea works, irrespective of the results they present on their site.  Let’s hop to it!

Phase 1: Plan & Design

1. Trading Idea

The idea is simple:

  • Buy when the MACD is below zero and crosses over the signal line
  • Sell short when the MACD is above zero and crosses below signal line
  • This is an ‘always in’ system
  • There are no trailing stops or stop losses
  • There are no profit targets
  • Optimize all three MACD inputs.

I will only test on equities, as they do.

2. System Definition

Position Sizing:

I will use the following position sizing:

  • Stocks/equities: $10,000 per position
  • Stocks/equities: $10,000 per position

Input Parameters:

InputData TypeDefaultDescription
FastLengthInteger5Number of bars for the fast MACD line
SlowLengthInteger10Number of bars for the slow MACD line
MACDLengthInteger1Number of bars for MACD average, a/k/a signal line


VariableData TypeDefaultCalculation
MyMACDDouble0Moving Average Convergence Divergence calculation
MACDAvgDouble0Exponential Moving Average (EMA) of MACD
NumSharesInteger0Number of shares for position: $10,000 / Close price , rounded to the nearest 1

Note: All MACD calculations use Exponential Moving Average (EMA) calculations


  • Long:
    • If current position is flat or short and
    • MACD < 0 and
    • MACD crosses over MACDAvg
    • Buy next bar at market
  • Short:
    • If current position is flat or long and
    • MACD > 0 and
    • MACD crosses under MACDAvg
    • Sell short next bar at market
  • Profit targets: None
  • Stop Loss: None

Challenges: None. 

3. Performance Objectives

The system will meet the following objectives:

System Type (trend, mean-reversion, day, swing, etc.)Trend following
Walk-forward Efficiency> 50%
Risk of Ruin0%
Profit Factor>= 1.5
Win Percent>= 30%
Max Drawdown %< 35%
Profit/Drawdown Ratio>= 2.0
Ready Date2021/05/14

This idea is S.M.A.R.T.: Specific, Measurable, Achievable, Realistic, Time-bound

4. Market Selection


EnergiesCurrenciesFixed IncomeAgricultureMetalsSoftsIndexesEquities


Market SectorInstrumentSymbolComments
EquitiesRandom equities from S&PAMD, CAT, CL, COP, CPB, CVS, CVX, D, DE, DHI, DHR, DRI, DTE, ED, EIX, ES, ETN, ETR, EXC, F, FCX, FE, FITB, GD, GE, GLW, HAL, HBAN, HIG, HOG, HSY, HUM, IBM, IP, JNPR, K, KMB, KO, KR, KSS, L, LEG, LHX, M, MAR, MCK, MCO, MET, MKC, MMM, MO, MRK, MS, MSI, MTBThis is the same set used for the Optimized CCI system; random select of stocks over 20 years.

Chart Type, Timeframe, Session, Time Zone:

Chart TypeRegular CandlestickCharting is only useful for validating entry and exit signals
Timeframe / Interval(s)Daily 
Time ZoneExchange 

Phase 2: Build

5. Manual Test

I walked through some symbols and this worked well enough to proceed. This system idea is really simple.

6. Build

Process Diagram



7. Unit Test

The unit test went fine, and everything works as expected. 


Note: Unit Test verifies that the system is executing the trading rules correctly.  It is, essentially, quality control.

Phase 3: Test

8. Optimization

I optimized the three parameters, following the rules provided by :

  • FastLength: 1-25, step 1
  • SlowLength: 3-45, step 1
  • MACDLength: 1-15, step 1

There are a couple problems here. Firstly, the large number of combinations (iterations), 16,125, is concerning.  I am concerned that the large number will lead to overfitting, which is where we get too granular and is a recipe for system failure.  This high number makes optimization processor intensive, is time-consuming, and generates a lot of data.  This is compounded by the fact that Moving Average Convergence Divergence is generally computationally intensive, as we are calculating an EMA 3 times: fast, slow, and average.

Secondly, I found an issue where the optimization engine would sometimes return results where the FastLength was larger than the SlowLength.  I tried a few things and I think I fixed it by not allowing trades where FastLength > SlowLength. 

I performed optimization on two different platforms; a 32-bit trading application and a 64-bit application.  The difference in optimization between the two was huge: 45 minutes for 32-bit and 3 minutes for 64-bit, a factor of 15 reduction in optimization time. 

9. Walk-Forward Analysis

One thing that I look at during optimization and walk-forward analysis is the walk-forward efficiency.  Walk-forward efficiency tells us if optimizing parameters has a positive effect on the system, as opposed to a random set of numbers. Below, I show how one stock, GLW (Corning), looks after optimizing this system:

In one case, row 6, had the optimal set of parameters, which is what the optimization engine found when it ran the numbers in row 7, or in other words, 100% efficiency. To find walk-forward efficiency, I took the value in the OOS column row 6, and divide by the IS column row 7, to get your value.  The average for all of the examples show above was 26%, which is well below my target of 50% set in the Objectives section.

There is another thing, as I saw with the TASC CCI system: being caught on the wrong side as the trend changes and not having an escape plan.  In the example below, the first signal is good, but the second signal on the right gets us in a short position as expected, but the market turns against us and we are stuck there.

I can think of a couple ways to mitigate this issue, but I feel a sense of déjà vu, as if I have been here before and I do not remember it ending well.   

None of the equities passed, failing at either one or both data points:

  • Walk-forward Efficiency, all symbols were well below the 50% minimum
  • Profit Factor, most symbols were >= 2.0, about 90% of the symbols

Why did so many pass with Profit Factor, but fail with Walk-Forward Efficiency? 

This could be selection or survivorship bias on my part.  If they are in the S&P 500, there is a good reason they got there: they are winners.  The failure in Walk-Forward Efficiency just tells me that I could probably select some random inputs and do almost as well.  This is the ‘monkey at a keyboard’ situation: a monkey at a keyboard randomly making trades could be a successful trader, purely by chance.  I think MACD can be good enough with some symbols regardless of the parameters.

Another reason for failure of the parameters may be the long lookback period, which is about two years.  With that in mind, I took one symbol, DRI (Darden Restaurants), to see if testing a range of lookback periods (50 – 250 days, in increments of 50) would improve walk-forward efficiency.  Here were the best results:

  • Profit Factor (Out of Sample): 4.06
  • Walk-Forward Efficiency: < 10%

I even tried a 50-day lookback period with DHR (Danaher), but the efficiency was still way below 50%.

No symbols passed, so this idea fails.

10. Monte Carlo Simulation

Nothing passed, so not Monte Carlo Simulation this time.

11. Incubation

We did not make it this far. 

Phase 4: Deploy

We did not make it this far.

Trading System Result: FAIL

Notes and Commentary

The final TASC system failed to pass through our development process.  The weakness in this system is with the inability to exit a bad trade. 

As I do every other week, I pose the question: Can this system be improved?  Perhaps.  Here are some ideas for future systems:

  • Use a stop-and-reverse method when caught on the wrong side
  • Use a stop, such as ATR, to determine when we are caught on the wrong side and stay flat until the next signal

There are glimmers of hope with this system, but there are issues that need to be resolved for this to be tradable.  Anyone who has tried to build a Moving Average Convergence Divergence system knows how difficult it is to create a working system.  Heck, any system is difficult.  This one, doubly so. 

One final thought.

If I put these in a portfolio, like last times’s 40in20out idea, would this system perform well? Nothing is going to fix the walk-forward efficiency issue, but it is possible that this would work well in a portfolio. There were stocks that had very good profit factors (>2.0), so this may be something that I explore in the future.

There you have it: three TASC systems, three failures.  They are interesting, but they cannot be traded as-is, at least for single equities.  It may be that combining them into a portfolio might smooth the equity curve, but optimization seems as useful as a coin-flip.  Anyhow, now we know what to make of these optimized systems.

I sincerely thank you for taking the time to read this article.  If you want to stay informed about each new trading idea I test, subscribe to my semimonthly newsletter (below).  If you have an idea you would like to build and test, feel free to leave a comment or reach me on the Comments page and we can discuss.

Next time’s idea: A Mystery Forex System…. In other words, I have no idea what I am going to do, but it will be with forex.  Tune in!


Did you like what you read? Do you want to see more?  Subscribe now and receive our email twice per month, with a new Trading System Idea and other fun stuff.

Don’t worry, we will never, ever, ever sell, overuse, or donate your email address. Promise.

Did you like what you read? Do you want to see more?  Subscribe now and receive our email twice per month, with a new Trading System Idea and other fun stuff.

Don’t worry, we will never, ever, ever sell, overuse, or donate your email address. Promise.

Leave a Reply

Your email address will not be published. Required fields are marked *