Innovative RSI-MACD Trading Strategies: A Comprehensive Guide
Written on
Introduction to the RSI MACD Oscillator
In the world of trading, innovation is crucial, and our quest for effective strategies helps us invest with confidence. Technical indicators are vital tools in the realm of Technical Analysis, proving invaluable for both discretionary and systematic trading approaches. In this article, we will explore an intriguing concept: the fusion of two renowned indicators, the Relative Strength Index (RSI) and the MACD Oscillator. We will begin by discussing the fundamentals of each, delve into the rationale behind the RSI-MACD combination, and conclude with a back-testing analysis.
As a point of interest, I recently published a new book following the success of my earlier work, "Trend Following Strategies in Python." This latest book offers advanced contrarian indicators and strategies, complete with a dedicated GitHub repository for ongoing code updates. If you're intrigued, check out the Amazon link below, or find the PDF version at the end of the article.
Understanding the MACD
The Moving Average Convergence Divergence (MACD) is arguably the second most recognized oscillator, following the RSI closely in popularity. Traders frequently utilize it for spotting divergences and market shifts. While many consider it a trend-following tool, others employ graphical analysis for identifying reversal points, making the MACD a versatile indicator.
The MACD calculation involves determining the difference between the 26-period Exponential Moving Average (EMA) and the 12-period EMA applied to closing prices. The resultant value is the MACD line, while the 9-period EMA of this value serves as the MACD signal, which we will utilize during back-testing.
To implement the EMA in Python, you can refer to the following function:
def add_column(data, times):
for i in range(1, times + 1):
new = np.zeros((len(data), 1), dtype=float)
data = np.append(data, new, axis=1)
return data
For a complete MACD function based on an OHLC array, consider this example:
def macd(data, close, long_ema, short_ema, signal_ema, position):
data = add_column(data, 1)
data = ema(data, 2, long_ema, close, position)
data = ema(data, 2, short_ema, close, position + 1)
data[:, position + 2] = data[:, position + 1] - data[:, position]
data = delete_row(data, long_ema)
data = ema(data, 2, signal_ema, position + 2, position + 3)
data = delete_column(data, position, 2)
data = delete_row(data, signal_ema)
return data
It’s essential to grasp the concepts rather than focusing solely on the code. Most of my strategies are documented in my books. Understanding the techniques and methodologies is paramount.
Video Introduction:
The Relative Strength Index Explained
Initially introduced by J. Welles Wilder Jr., the RSI is a highly popular and adaptable technical indicator. It primarily serves as a contrarian indicator, where extreme values indicate potential market reactions. The calculation of the standard RSI involves:
- Assessing the change in closing prices compared to previous values.
- Separating positive changes from negative ones.
- Computing a smoothed moving average of both positive net changes and the absolute values of negative net changes.
- Dividing the smoothed positive values by the smoothed negative values to derive the Relative Strength (RS).
- Applying a normalization formula for each time step to compute the RSI.
When coding the RSI in Python, you will need an OHLC array structured as follows:
def rsi(data, lookback, close, position):
data = add_column(data, 5)
for i in range(len(data)):
data[i, position] = data[i, close] - data[i - 1, close]# Further processing...
return data
Visual Representation:
Combining RSI with MACD
The MACD operates as an unbounded indicator, which makes the concept of applying the RSI formula to it particularly interesting. By constraining MACD values between 0 and 100 using the RSI formula, we aim to create a more interpretable signal.
For implementation, when applying the MACD to market prices, the RSI function should be applied to the results obtained from the MACD function.
Video Insight:
Developing a Trading Strategy with RSI-MACD
The proposed trading strategy is straightforward: - A long (buy) signal is triggered whenever the RSI MACD exceeds 5 after being below this threshold. - A short (sell) signal is activated when the RSI MACD drops below 95 after previously being above it.
def signal(data, rsi_macd_column, buy_column, sell_column):
data = add_column(data, 5)
for i in range(len(data)):
try:
if data[i, rsi_macd_column] > lower_barrier and data[i - 1, rsi_macd_column] < lower_barrier:
data[i + 1, buy_column] = 1elif data[i, rsi_macd_column] < upper_barrier and data[i - 1, rsi_macd_column] > upper_barrier:
data[i + 1, sell_column] = -1except IndexError:
passreturn data
Conclusion In conclusion, my aim is to contribute to the realm of objective technical analysis by promoting transparent techniques and strategies that require back-testing before implementation. This approach enhances the credibility of technical analysis, which often suffers from perceptions of subjectivity.
Whenever you encounter a trading technique or strategy, always: 1. Approach with a critical mindset and eliminate emotional bias. 2. Back-test using realistic simulations. 3. Optimize and conduct forward testing if potential is identified. 4. Account for transaction costs and slippage in your tests. 5. Incorporate risk management and position sizing.
Even after taking these precautions, remain vigilant and monitor the strategy, as market dynamics can change, rendering previously profitable strategies ineffective.
For those interested, the PDF version of my book is available for 9.99 EUR. Please include your email when purchasing to ensure proper delivery. Once received, you can download it from Google Drive.