The "AverageStrategy" is a trading strategy implemented in Python for backtesting purposes. It is a basic strategy that buys and sells assets based on crossovers of two moving averages. Here's a breakdown of its key components:
The strategy uses two exponential moving averages (EMA) as indicators: a shorter-term EMA with a time period of 8 and a medium-term EMA with a time period of 21.
In the populate_indicators method, these two moving averages (maShort and maMedium) are calculated and added to the input dataframe for further analysis.
The populate_buy_trend method determines the buy signals based on the crossover of the maShort and maMedium moving averages.
When the shorter-term EMA crosses above the medium-term EMA, a buy signal is generated. The populate_sell_trend method identifies the sell signals based on the crossover of the maMedium and maShort moving averages. When the medium-term EMA crosses above the shorter-term EMA, a sell signal is generated. The strategy also defines some additional parameters:
minimal_roi specifies the desired minimum return on investment (ROI) for the strategy. In this case, it is set to 0.5, meaning a trade should be closed if it reaches a 50% ROI. stoploss defines the optimal stop loss level for the strategy. If the trade goes against the expected direction by 20% (negative value), it will be closed with a stop loss. timeframe indicates the preferred timeframe for the strategy's analysis, which is set to 4 hours. It's worth noting that the author mentions this strategy doesn't perform well and is primarily a proof of concept.