Home Creators Posts Import Register Favorites Logout
haven't archived this post yet. have a subscription? use the importer!

Downloads

  • bb_riding-file.7z

Missing 1 file, as this post has not yet been imported.

Content

Introduction

Hello there, and welcome back to another post where I will test another trading strategy. And this time we are going to ride the Bollinger bands.

It is one of my own older strategies that I developed a long time ago and I recently found it again when I was reorganizing and cleaning stuff up for this backtesting video series.

So let’s see if this strategy will be good for trading with the help of a trading bot.

Where to find this strategy

You can use it yourself or can build upon it to create even better performing bot trading strategies.

Now, Let’s see how this strategy works.

How the strategy works

This strategy is rather well known and I think it was first described by John Bollinger himself in his book “Bollinger on Bollinger bands”.

What this strategy intends to do is to buy an asset when the price aggressively moves up and above the upper Bollinger band. This indicates strong market momentum and the possibility that prices could go higher.

A lot of people try to buy below the lower band and sell when the price is above the upper band. Which in itself is a totally different strategy. However This band's riding strategy is one for trend followers and faders.

At some point the trend will be exhausted and profits should be taken. These moments are also determined in this strategy.

So,

This strategy has a couple of simple rules to follow.

Entry:

  • It buys when the price closes above the upper Bollinger band.
  • I use another indicator here that also looks at the width of the band. If the band also widens above a certain amount, then the momentum is really there. This prevents fake movements with tight price closes above the Bollinger band but without the positive momentum in the market.

Exit:

There are three ways this strategy exits a trade.

  • The first is ofcourse the stoploss moment, for the times the trade did not go as expected.
  • The second exit signal is the ROI setting of the trading bot.
  • And the third and additional exit indicator which I use here is the MACD indicator. When the MACD signal line get’s below 0, then the trend has been exhausted and we can exit the trade.

So, in short. There are buy signals when the price closes above the higher Bollinger band and the bands widen above a certain amount.

And the bot sells when momentum disappears, which is indicated by the macd signal line that gets below the 0 line.

Or the ROI point with a predefined profit point get’s hit.

Or the stoploss point get’s hit.

Browsing the code

How does this look in the code:

We start with defining our first and only profit point. Which states that, if the profit reaches 30% of the initial buy price, then sell the position and lock in profits.

The second parameter is the stop loss point. This states that, If at any moment there is a loss of 23,5% after the initial buy. Then sell the position. This trade has gone bad.

And here is the timeframe where the strategy was built for. But I know that this is not always the best timeframe after testing. Let’s leave it at this and move on with the next part and that is where the parameters are defined.

You can see here that the Bollinger bands parameter is configured. This is the default Bollinger bands setup with the default 20 simple moving average.

Then we calculate the width of the band which is the upper band price minus the lower band price and that divides by the moving average used.

And finally we configure the MACD indicator with its default values. And these are configured in the TA library itself.

There is a little print statement to show you the output of the dataframe to your terminal window. This way you can check if the calculations are made correctly by the bot. These are commented out, but you can uncomment these to see what happens on your screen when backtesting.

Then next there is the main strategy setup.

Here the buy and sell signals are defined.

And as you can see, the pseudo code from earlier is coded in real Python code that the bot can read and use.

This buy section checks if the close price is above the upper Bollinger band and this checks if the band is higher than 0.02. If it is below 0.02, then there is not enough momentum and the bot will not buy.

And finally hee, this sell function tells the bot to sell the position if the MACD signal line gets below 0. The trend has lost its momentum and the position can be sold.

So, there you have it. A simple Bollinger bands riding strategy coded into trading bot code so that you do not have to do this manually.

Let’s find out in our initial backtest how this performs on backtesting data.

Initial backtest results

It is very nice to see a working strategy, which is easy to understand and that is also getting nice profits against a modest risk after some time.

And as much as I like the gains on the 4 hour and 1 hour timeframe. I must say that my sheet tells me to stick to the 1 day timeframe due to the lower drawdown, higher win rate and useability on 77% of top 50 coins I have configured.

If we take a closer look at the exit reasons stats, then we see that the ROI and stoploss settings have the most influence on the results on this timeframe.

So if I want to make this strategy more optimized, then adjusting the ROI and stop loss would possibly make the biggest difference here.

HYPEROPTIMIZED PARAMETERS BACKTEST RESULTS

Changing the settings of the ROI and stop loss significantly increased the performance of this strategy.

Changing the ROI from only 30% to some time based stop loss settings. Where one of them even instructs to take profit after a 100% gain made this strategy's performance really impressive in my opinion.

Also, changing the stop loss from 23 to almost 35% apparently caused this strategy not to stop out many times but let the exit signal determine where to exit the trade.

Although I am not a big supporter of wide stop loss settings, apparently this worked for this strategy. If I would use this strategy, I would try to investigate further how to negate this risk.

Nonetheless the exit signal did a good job because it stopped out a trade before it got bigger losses. And in the end it had lesser negative profits than the earlier stop loss setting as you can see in this overview.

So, all in all, I am very curious where this strategy enters into the overall strategy league.

STRATEGY LEAGUE

Riding the bands enters the total league on the 6th place. And this is a very pleasant surprise after having a range of strategies tested that could not even enter this league in the upper half.

Band riding has not the highest gains, but its win rate is very admirable which also results in a medium risk of ruin. I doubt if I can ever find a better win rate than the NFIX strategy but that one has a much lower profit

A little bit of more risk taking can really make the difference between a hobby or an income. And it's all on your own preference which strategy you will use at the end.

Comments

No comments found for this post.