MACD and Stochastic Trading Strategy

When technical analysts talk about the two most compatible and easy to use indicators, the first thought which comes to their mind is the Moving Average Convergence-Divergence (MACD) and the Stochastic Indicator.

The analysts believe that this combination works because the stochastic is comparing a stock’s closing price to its price range over a certain period of time, while the MACD is the formation of two moving averages diverging from and converging with each other. If used to its fullest potential, this active amalgamation is extremely effective in the right time frame.

The following is a fairly straightforward double cross trading strategy that makes use of MACD to decide the predominant trend and stochastic indicator to generate buy/sell signals.


Moving Average Convergence Divergence (MACD) is a trend-following momentum indicator that shows the relationship between two moving averages of the market price. The MACD is calculated by subtracting the 26-period Exponential Moving Average (EMA) from the 12-period EMA.

A nine-day EMA of the MACD called the “signal line” is then plotted on top of the MACD line, which can function as a trigger for buy and sell signals.

The 12-period EMA is a more volatile faster moving average which closely follows the price. The 26-period EMA is the slower moving average and thus 12-period EMA being more than the 26-period EMA is a sign of strength whereas 12-period EMA being less than the 26-period EMA is a sign of weakness. Therefore, a positive MACD indicates bullishness whereas a negative MACD indicates bearishness.

Get $25 Joining Bonus On Mudrex


A stochastic oscillator is a momentum indicator comparing a particular closing price of a security to a range of its prices over a certain period of time. Just like MACD, stochastic also has a faster-moving metric and a slower-moving metric.

The following is the formula for calculating the slow-stochastic indicator called %K:

Stochastic indicator formula

C = Most recent closing price
L14 = Lowest price traded in past 14 trading sessions
H14 = Highest price traded in the past 14 trading sessions
%K = Current value of the stochastic indicator

The fast-stochastic indicator is taken as %D = 3-period moving average of %K.

The general theory serving as the foundation for this indicator is that in a market trending upward, prices will close near the high, and in a market trending downward, prices close near the low. And hence in a range of 0-100, 80+ is considered as overbought indicating an upcoming downtrend while 20- is considered to be oversold indicating an upcoming uptrend.

Buy/sell signals can be generated using the crossovers of %K and %D but we’ll be using the overbought and oversold thresholds for our strategy.

How to Setup MACD and Stochastic Trading Strategy?

For the sake of standardisation and simplicity, we’ll be using the default look-back periods for both MACD and Stochastic. We’ll use the difference of 12-period EMA and 26-period EMA in the case of MACD to set the predominant trend and threshold values of 20 and 80 of the 14-period stochastic indicator to generate buy/sell signals.

Defining a Bullish Scenario

  1. Predominant uptrend is confirmed when MACD is positive which means 12-period EMA > 26-period EMA which is a sign of strength
  2. Enter the trade as soon as the stochastic indicator dips below 20 and rises again so that we enter right at the bottom of the upcoming uptrend thus maximizing profits

Defining a Bearish Scenario

  1. A predominant downtrend is confirmed when MACD is negative which means 12-period EMA < 26-period EMA which is a sign of weakness
  2. Exit the trade as soon as the stochastic indicator soars above 80 and comes down so that we exit the trade right at the top of the upcoming downtrend thus maximizing profits
MACD and stochastic candlestick chart
Look at the Buy and Sell signals generated according to the conditions defined above

Building MACD and Stochastic Trading Strategy on Mudrex

Say no to manually setting up your trades by making your auto-trading bot within minutes on Mudrex. The Mudrex platform helps traders automate their trading and hence helps you execute your trading without any hassle! You can create strategies on Mudrex using simple blocks. You can connect multiple blocks and define conditions on those connections or paths to create your strategy on Mudrex.

Invest With Mudrex

As discussed above, to build the MACD and Stochastic Trading Strategy, let us first write our entry/exit conditions so that we know what to do while building our strategy:

Buy when:

  • MACD > 0
  • %K crosses up 20

Sell when:

  • MACD < 0
  • %K crosses down 80

We’ll use a stop loss of 10% to prevent losses due to any false signals generated. Stop loss helps improve the percentage of trades won, by a good margin. Choosing the value of stop-loss depends on how much risk you’re willing to take and how volatile the market is.

The strategy looks pretty intuitive and can be easily constructed by using a couple of indicator blocks as follows. We’ll use the MACD indicator block to make the first buy condition MACD > 0:

macd indicator block

To make the 2nd buy condition, we set the %K output crossing up 20 in the stochastic oscillator block:

stochastic indicator block

Connecting the two using an “AND” block to generate the buy signal:

strategy buy signal

Similarly, creating a sell signal by defining MACD < 0 and %K crossing down 80 is left as an exercise.

Set up a stop loss of 10% by clicking the stop loss tab on the left panel:

stop loss

The overall strategy with sell signal and stop loss looks like this:

macd and stochastic trading strategy
Overall Strategy

This is how easy it is to build your own profit-generating strategies on Mudrex within minutes!

We can now run a quick back-test to see how our strategy performs. Running one from over the past 3 months using a tick cycle of 2H gives us pretty convincing results doubling our returns with a Sharpe Ratio of 2.81 and a win ratio of 2/3rd:

Backtest from 22nd Jan 2020 to 22nd April 2020 using a 2H tick cycle on Bitmex BTC/USD

The advantage of this strategy is it gives traders an opportunity to hold out for a better entry point on up-trending stock or to be surer any downtrend is truly reversing itself when bottom-fishing for long-term holds. Because the stock generally takes a longer time to line up in the best buying position, the actual trading of the stock occurs less frequently, so you may need a larger basket of stocks to watch.

You may also want to add a relative strength index (RSI) indicator into the mix or make use of the signal line of MACD or %D line of the stochastic indicator to generate buy/sell signals.

A lot of even more complex things can be done on Mudrex! Signup today!


A few quick references below:

Happy Trading!

Latest stories

You might also like...