Skip to content

MACD Crossover

This is a trading strategy called "MACD Crossovers" implemented in Python using the PyAlgoTrading library. The strategy is based on the MACD indicator crossover.

MACD Crossover

In the dynamic world of stock trading, mastering effective strategies is the key to success. The Moving Average Convergence Divergence (MACD) Crossover strategy is a powerful tool that can help traders identify potential entry and exit points in the stock market.

Here is a summary of RSI and MACD in the stock market: - The MACD is a trend-following momentum indicator that consists of two lines: the MACD line and the Signal line. - A bullish signal is generated when the MACD line crosses above the Signal line, indicating a potential uptrend. - Conversely, a bearish signal occurs when the MACD line crosses below the Signal line, suggesting a potential downtrend. - When the MACD crosses above the Signal line, it's a signal to consider a long (BUY) position. - Conversely, when the MACD crosses below the Signal line, it may be time to think about a short (SELL) position.

Strategy Overview

The MACD Crossover strategy is a robust approach that leverages the power of the MACD indicator to identify potential entry and exit points in the stock market.

Strategy Parameters

The following parameters can be configured for the strategy:

Name Default Value Expected Value Description
TIMEPERIOD_FAST None greater than 0 Period (number of candles) by which EMA 2 is calculated
TIMEPERIOD_SLOW None greater than 0 Period (number of candles) by which EMA 2 is calculated
TIMEPERIOD_SIGNAL None greater than 0 Period (number of candles) by which moving average is calculated

Crossover Calculation

The get_crossover_value method calculates the crossover value based on the inverse crossover of the two EMAs of the closing prices. It uses the talib.MACD function from the Talib library to calculate the MACDs. The method then determines the crossover between the two MACDs and returns the corresponding value (-1, 0, or 1).


Last update: 2024-08-03