IbkrApi.Backtester.Strategies.MA (ibkr_api v1.0.0)
View SourceSimple Moving Average crossover strategy.
Generates buy signals when price is above the moving average and sell signals when price is below the moving average.
Summary
Functions
Calculates Simple Moving Average for the given bars.
Initialize the strategy with configuration options.
Generates trading signals based on moving average crossover.
Functions
@spec calculate_sma([IbkrApi.Backtester.Bar.t()], pos_integer()) :: float()
Calculates Simple Moving Average for the given bars.
Parameters
bars
: List of bars (most recent first)window
: Number of periods to average
Examples
iex> bars = [%{close: 100}, %{close: 102}, %{close: 98}]
iex> IbkrApi.Backtester.Strategies.MA.calculate_sma(bars, 3)
100.0
Initialize the strategy with configuration options.
Options
:window
- Moving average window size (default: 5)
Examples
iex> IbkrApi.Backtester.Strategies.MA.init(window: 10)
%{window: 10}
Generates trading signals based on moving average crossover.
Logic
- Buy when current price > moving average
- Sell when current price < moving average
- Hold when price equals moving average or insufficient data