Skip to content

Macd


class backtide.strategies.Macd(fast_period=12, slow_period=26, signal_period=9)

Moving Average Convergence Divergence crossover strategy.

Buys on a MACD golden cross (MACD line crosses above the signal line) and sells on a death cross (MACD line crosses below the signal line). Captures medium-term trend changes driven by the divergence between fast and slow exponential moving averages. Useful for trend-following in moderately trending markets.

Parameters

fast_period : int, default=12

Fast EMA period.

slow_period : int, default=26
Slow EMA period.

signal_period : int, default=9
Signal line EMA period.

Attributes

name : str

Human-readable strategy name.

is_multi_asset : bool
Whether this is a multi-asset strategy.


See Also

Momentum

Trend-following strategy driven by short-term price momentum.

SmaCrossover

Simple Moving Average crossover strategy using fast and slow periods.

Rsi

Relative Strength Index combined with Bollinger Bands for dual confirmation.


Methods

description Short explanation of what the strategy does.
evaluate Evaluate the strategy and return orders.
required_indicators Indicators that must be computed up-front for this strategy.


method description()

Short explanation of what the strategy does.

Returns

str

The description.



method evaluate(data, portfolio, state, indicators=None)

Evaluate the strategy and return orders.

Parameters

data : dict[str, np.array | pd.DataFrame | pl.DataFrame]

Keys are the experiment's symbols and values are the historical OHLCV data available up to the current bar.

portfolio : Portfolio
Current portfolio holdings (cash, positions and open orders).

state : State
Current simulation state.

indicators : dict[str, dict[str, np.array | pd.DataFrame | pl.DataFrame]] | None
The first keys are the indicator names. The second keys are the experiment's symbols. The values are the pre-computed indicator values. None if no indicators were selected.

Returns

list[Order]

Orders to place this tick.



method required_indicators()

Indicators that must be computed up-front for this strategy.

Returns a list of indicator instances, already parameterized with this strategy's current settings, that the engine will auto-include before the backtest starts.

Returns

list[BaseIndicator]

The required indicator instances.