The BB_RSI strategy is a backtesting strategy for trading. It uses a combination of Bollinger Bands and the Relative Strength Index (RSI) indicators to generate buy and sell signals. Here's a breakdown of what the strategy does:
It calculates the RSI indicator using the ta.RSI function and adds it as a column called 'rsi' to the dataframe.
It calculates the Bollinger Bands using the qtpylib.bollinger_bands function with a window size of 20 and standard deviation of 2.
It adds the lower, middle, and upper bands as columns to the dataframe: 'bb_lowerband', 'bb_middleband', and 'bb_upperband'.
It calculates additional Bollinger Bands with a standard deviation of 3 and adds them as columns to the dataframe: 'bb_lowerband3', 'bb_middleband3', and 'bb_upperband3'. In the populate_buy_trend method, it generates buy signals when the RSI is greater than 33 and the closing price is below the lower band of the Bollinger Bands with 3 standard deviations. In the populate_sell_trend method, it generates sell signals when the closing price is above the lower band of the Bollinger Bands with 2 standard deviations and the RSI is greater than 91. The strategy also defines other parameters such as the minimal return on investment (ROI), stop loss value, ticker interval, order types, and time in force for orders. Overall, the strategy aims to identify potential buying opportunities when the price is relatively low and the RSI is not extremely overbought, and to identify selling opportunities when the price is above the lower Bollinger Band and the RSI is in the overbought territory.