The MACDRSI strategy is a backtesting strategy that combines the use of the Moving Average Convergence Divergence (MACD) and Relative Strength Index (RSI) indicators to generate buy and sell signals for trading. In this strategy, the following indicators are calculated and used:
MACD: Two MACD indicators are calculated with different parameters. The first MACD indicator uses a fast period of 5 and a slow period of 15, while the second MACD indicator uses a fast period of 12 and a slow period of 26.
The MACD line, MACD signal line, and MACD histogram values are extracted from these indicators.
RSI: The Relative Strength Index is calculated using the default parameters.
The RSI value is used as an additional condition for generating buy signals. The strategy defines the following key components:
Minimal ROI: It specifies the desired minimum return on investment for the strategy at different time intervals. Stoploss: It sets the optimal stop loss value for the strategy. A stop loss of -0.10 means that if the price drops by 10% from the entry price, the position will be sold. Ticker Interval: It sets the optimal interval for the ticker data. In this case, the strategy is designed to work with 15-minute intervals. The strategy then implements the following methods to generate buy and sell signals:
populate_indicators(): This method is responsible for populating the indicators in the DataFrame. It calculates the MACD and RSI indicators and adds them as columns in the DataFrame. populate_buy_trend(): This method populates the buy signal in the DataFrame based on the defined conditions. The buy signal is generated when the RSI value is between 30 and 70, the MACD histogram values are positive and transitioning from positive to negative, and the second MACD histogram is negative and decreasing over multiple periods. populate_sell_trend(): This method populates the sell signal in the DataFrame based on the condition that the first MACD line crosses below the MACD signal line. By backtesting this strategy on historical data, you can evaluate its performance and determine its effectiveness in generating profitable trading signals.