We have decided to give EVERYTHING for free! What are you waiting for?

LOGIN

There are multiple ideas that you can use to trade with Bollinger bands. First, we need to know if we’re going to use Talib Bollinger bands or qtpylib. For this example, I’ll choose qtpylib Bollinger bands and the RSI provided by Talib library.

To check the indicators available in qtpylib you can check here: https://github.com/freqtrade/freqtrade/blob/develop/freqtrade/vendor/qtpylib/indicators.py

The Bollinger band code is the following:

def bollinger_bands(series, window=20, stds=2):
    ma = rolling_mean(series, window=window, min_periods=1)
    std = rolling_std(series, window=window, min_periods=1)
    upper = ma + std * stds
    lower = ma - std * stds

    return pd.DataFrame(index=series.index, data={
        'upper': upper,
        'mid': ma,
        'lower': lower
    })

Which we can use in the strategy.py on freqtrade/user_data/strategies/, for this example let’s copy the test_strategy.py and re-name it to bbrsi.py

Open bbrsi.py, modify the class name, from class TestStrategy(IStrategy) to class bbrsi(IStrategy), now we want to be able to take profits from roughly 5% to 7%, but we’ll also include different sell parameters. For instance, to modify the profit part, we’ll this section of the strategy:

minimal_roi = {
        "40": 0.0,
        "30": 0.01,
        "20": 0.02,
        "0": 0.04
    }

to

  minimal_roi = {
        "0": 0.07
    }

Modify stoploss = -0.10 to -3.5% so it will be stoploss = -0.035, we’ll be using sell signal, so search for the line use_sell_signal and change from False to True

We need now to modify the populate indicator section, look for the line
def populate_indicators(self, data frame: DataFrame, metadata: dict) -> DataFrame:

then proceed to comment all indicators that we won’t use, in this example ADX is not commented so we’ll remove it by adding # in front of dataframe[‘adx’]…; do the same for other indicators, the Bollinger bands section should look like this:

bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']
        dataframe['bb_middleband'] = bollinger['mid']
        dataframe['bb_upperband'] = bollinger['upper']

And, the RSI section should look like this:
dataframe['rsi'] = ta.RSI(dataframe)

Now we’ll look for def populate_buy_trend in order to create the logic behind our algorithm or strategy. As you can see in the picture:

[tv-ideaview idea=”5QxRbp7F” width=”980″ height=”980″ language=”en”]

We want it to buy if the price of the candle before the current candle was outside the Bollinger bands AND the new candle close is now inside the Bollinger band range AND if RSI < 50. For example, this is how the code looks like (this section of the code has to be inside def populate_buy_trend function:

dataframe.loc[
	(
		(dataframe[‘close’].shift(1)<dataframe[‘bb_lowerband’]) & 
		(dataframe[‘close’] > dataframe[‘bb_lowerband’]) &
		(dataframe[‘rsi’] < 50)
	),
	‘buy’] = 1

To sell we can use different targets, we already sell at 7% profit as market in the ROI section. To sum up, we just include other sell possibilities, like sell if the candle closes outside of the top Bollinger band or if RSI > 60.

We put the following code in the def populate_sell_trend function:

dataframe.loc[ 
	(
		(dataframe[‘close’]>dataframe[‘bb_upperband’]) | 
		(dataframe[‘rsi’] > 60)
	),
	‘sell’] = 1

However, this is just an example of how to create a simple strategy by looking at the indicators on Tradingview. Remember to modify them accordingly, to include fail-safe options.

Backtest the strategy and do dry-runs to make sure it’s profitable, feel free to comment if you have any questions!.

3 Comments
  • Servando Garcia
    10:35 AM, August 2019

    Great article, less than an hour after I implemented this strategy. I turned a profit. Thank you

    • CryptoCue
      10:39 AM, August 2019

      Thanks, do know that this might not be profitable in the long run.

  • Mustakim
    2:54 PM, July 2020

    It mean we are going to buy if price fall 1% bb_lowerband below where rsi less then 50.
    i think this strategy work fine if the market goes flash crash situation.

Leave a Reply

Your email address will not be published. Required fields are marked *