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:

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!.

2 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.

Leave a Reply

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

Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from Youtube
Vimeo
Consent to display content from Vimeo
Google Maps
Consent to display content from Google
Spotify
Consent to display content from Spotify
Sound Cloud
Consent to display content from Sound
Cart Overview