turtle_quant_1.strategies.momentum.moving_average_con_div¶
turtle_quant_1.strategies.momentum.moving_average_con_div
¶
Moving average convergence divergence (MACD) strategy implementation.
MovingAverageConDiv
¶
Bases: BaseStrategy
Moving average convergence divergence strategy implementation.
Leading / Lagging: Lagging when converging. Leading when diverging.
Lag period (in candles): (slow_candles - 1) / 2 - (fast_candles - 1) / 2 + (signal_candles - 1) / 2
Effect: Delay in recognizing that a new trend has begun.
Initialize the MACD strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fast_candles
|
int
|
The number of candles for the fast EMA. |
12
|
slow_candles
|
int
|
The number of candles for the slow EMA. |
26
|
signal_candles
|
int
|
The smoothing window applied to the MACD line to form the signal line. |
9
|
Source code in src/turtle_quant_1/strategies/momentum/moving_average_con_div.py
generate_historical_scores
¶
Generate a historical score array for a symbol based on MACD.
NOTE: Assume that the data is sorted by datetime.
This strategy works best when resampled to daily data. Refer to: https://www.investopedia.com/terms/m/macd.asp
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame with OHLCV data. |
required |
symbol
|
str
|
The symbol being analyzed. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Score array with each value between -1.0 and +1.0, indexed by the original data's index. |
Source code in src/turtle_quant_1/strategies/momentum/moving_average_con_div.py
generate_prediction_score
¶
Generate a prediction score based on the latest MACD values.
NOTE: Assume that the data is sorted by datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
The data to use for the strategy. |
required |
symbol
|
str
|
The symbol to use for the strategy. |
required |
Returns:
| Type | Description |
|---|---|
float
|
A float between -1.0 and +1.0 representing the signal strength. |