The BBRSINaiveStrategy is a trading strategy that utilizes the concepts of Bollinger Bands and RSI (Relative Strength Index) to generate buy and sell signals. Here's a breakdown of what the strategy does:
In the populate_indicators method, the strategy calculates the RSI indicator for the given dataframe and adds it as a new column called 'rsi'. Additionally, it calculates the Bollinger Bands using a window size of 20 and a standard deviation of 2.
The upper band, middle band, and lower band values are stored in the respective columns: 'bb_upperband', 'bb_midband', and 'bb_lowerband'.
The modified dataframe is returned.
In the populate_buy_trend method, the strategy identifies potential buying opportunities based on two conditions:
RSI is greater than 25. The closing price is below the lower Bollinger Band. When both conditions are satisfied, the 'buy' column is set to 1 for the corresponding row. In the populate_sell_trend method, the strategy identifies potential selling opportunities based on two conditions:
RSI is greater than 70. The closing price is above the middle Bollinger Band. When both conditions are satisfied, the 'sell' column is set to 1 for the corresponding row. Each method modifies the original dataframe by adding the 'buy' or 'sell' column, indicating the presence of a buy or sell signal. The modified dataframe with the added columns is returned by each method. This strategy uses RSI to determine overbought (sell) and oversold (buy) conditions, along with Bollinger Bands to define the price range. When the price breaches the lower Bollinger Band and the RSI is greater than 25, it generates a buy signal. Conversely, when the price exceeds the middle Bollinger Band and the RSI is greater than 70, it generates a sell signal.