The SMAOffset strategy is a backtesting trading strategy that uses a Simple Moving Average (SMA) offset to generate buy and sell signals. Here's a breakdown of how the strategy works:
The strategy uses the talib library to calculate the SMA (Simple Moving Average) of the closing prices of the trading pair over a specified number of candles (base_nb_candles). Two offset values, low_offset and high_offset, are applied to the SMA to create lower and upper thresholds.
The strategy uses the Bollinger Bands indicator (qtpylib.bollinger_bands) to plot the upper, middle, and lower bands on the chart.
In the populate_buy_trend method, the strategy generates a buy signal when the closing price falls below the lower threshold (sma_30_offset) and the volume is greater than zero.
In the populate_sell_trend method, the strategy generates a sell signal when the closing price rises above the upper threshold (sma_30_offset_pos) and the volume is greater than zero. The strategy applies a stop-loss rule (custom_stoploss) that checks the current time, open date of the trade, and current profit. If the trade has been open for more than 1200 minutes (20 hours) and the current profit is less than -0.05, a custom stop-loss value of -0.001 is returned. Otherwise, the stop-loss value remains unchanged at 1. The strategy has a minimal return on investment (ROI) table, which sets the minimum desired ROI to 1. This means that the strategy aims to achieve a minimum return of 100% on each trade. The strategy has a static stop-loss value of -99, meaning that if the trade's profit drops below -99, it will be automatically closed. The strategy does not use a trailing stop. The strategy is optimized for a 5-minute timeframe. The strategy only processes new candles and requires a startup candle count of base_nb_candles. The strategy provides a configuration for plotting the SMA offset lines on the main chart. The strategy does not use a custom stop-loss. Overall, the SMAOffset strategy utilizes the SMA offset as a trend indicator to generate buy and sell signals based on the crossing of price thresholds.