The BBandsRSI strategy is a trading strategy that combines Bollinger Bands and the Relative Strength Index (RSI) to generate buy and sell signals. Here's a breakdown of what the strategy does:
In the populate_indicators method:
The RSI indicator is calculated using the price data in the dataframe and added as a new column called 'rsi'. 'sobre_comprado' (overbought) and 'sobre_vendido' (oversold) thresholds are set to 70 and 30, respectively.
Bollinger Bands are calculated using the typical price of the dataframe with a window of 20 and 2 standard deviations.
The lower band, middle band, and upper band values are added as new columns.
The 'bb_percent' column is calculated as the percentage of the close price relative to the Bollinger Bands. The 'bb_width' column is calculated as the width of the Bollinger Bands relative to the middle band. In the populate_buy_trend method:
If the RSI is below 30, the close price is below the lower Bollinger Band, and the volume is greater than 0, a buy signal is generated and marked as 1 in the 'buy' column. In the populate_sell_trend method:
If the RSI is above 70 and the volume is greater than 0, a sell signal is generated and marked as 1 in the 'sell' column. The strategy uses these indicators and conditions to determine when to buy and sell assets. The populate_indicators method calculates the necessary indicators, while the populate_buy_trend and populate_sell_trend methods generate the corresponding signals based on predefined conditions.