Trade Simulation Example
Below you will find how to set up a strategy using an example foun in the demo_examples folder.
Strategy Setup w/ Example Strategy
Once the TradingEngine
is initialized, you can apply a trading strategy to it. In this example, we use a MACDStrategy
to simulate trades based on the Moving Average Convergence Divergence (MACD) indicator.
Code for the MACDstrategy, located in demo_examples/strategies
:
MACD Strategy Constructor Arguments:
Argument
Type
Description
engine
TradingEngine
The initialized trading engine instance.
macd_params
dict
Dictionary containing the MACD parameters:
- short_period
int
The short-period EMA (typically 12 periods).
- long_period
int
The long-period EMA (typically 26 periods).
- signal_period
int
The signal line period (typically 9 periods).
Example Usage:
This sets up the MACD strategy using the specified MACD parameters and links it to the previously initialized TradingEngine
.
Applying the Strategy:
To apply the strategy, you need to add the following command to your script:
Full implementation example:
Last updated