The combined BinH and Culc algo strategy (Patreon)
Content
Introduction
Hi there and welcome to another post where I will discuss another algorithmic trading strategy for use with an automated crypto trading bot.
In earlier posts I discussed and tested the BinHV and Clucmay algo strategies. These strategies have both their own positive sides and drawbacks. The author of these strategies probably found it a good idea to combine best of both worlds into one single algo. So this time we will find out if combining two different strategies will create synergy and produce even better results than the individual single ones.
And as always the credits and kudo’s for creating and supplying us with this code is the Berlinguy in CA. The code is in the freqtrade repository for algo strategies which you can find over here.
At the moment I still have some of these files to test. However I am slowly starting to see the bottom of this jar of wonderfull inspiration. There are still a few left but the remainder are these files which primarily act as coding examples and do not really count as serious trading strategies.
Nonetheless, let’s not wander off and start by looking at the code to see what the intentions are of this file. And this time I will be a little bit more high over because you can watch the details of both these strategies in their own respective post and video.
The strategy
As always the first block of code are the external libraries and modules that are important and imported for this file.
# --- Do not remove these libs ---
import freqtrade.vendor.qtpylib.indicators as qtpylib
import numpy as np
# --------------------------------
import talib.abstract as ta
from freqtrade.strategy import IStrategy
from pandas import DataFrame
Then the bollinger bands are defined within this file. Why the bollinger bands from another ta library are not used is not clear to me. But nonetheless, now you know how you can code this yourself.
def bollinger_bands(stock_price, window_size, num_of_std):
rolling_mean = stock_price.rolling(window=window_size).mean()
rolling_std = stock_price.rolling(window=window_size).std()
lower_band = rolling_mean - (rolling_std * num_of_std)
return np.nan_to_num(rolling_mean), np.nan_to_num(lower_band)
Next comes the strategy class where all the magic happens.
Let’s first start with the standard items that are always present in each and every Freqtrade strategy file:
These are the Minimal ROI, which is set here to take profit at 5 percent gains.
The stoploss is also set to minus 5 percent losses. So this time the risk:reward setting is set to 1:1.
And the author decided that the 5 minute timeframe is the best for this strategy to use. And we will find out later if this really is the case.
And by the way, the author also states that the strategy performs best is there is a maximum of 2 open trades used. Also he was so friendly to give his own experiences with this strategy in this section. You should take note of his remarks before using or experimenting with your own setup here.
class CombinedBinHAndCluc(IStrategy):
# Based on a backtesting:
# - the best perfomance is reached with "max_open_trades" = 2 (in average for any market),
# so it is better to increase "stake_amount" value rather then "max_open_trades" to get more profit
# - if the market is constantly green(like in JAN 2018) the best performance is reached with
# "max_open_trades" = 2 and minimal_roi = 0.01
INTERFACE_VERSION: int = 3
minimal_roi = {
"0": 0.05
}
stoploss = -0.05
timeframe = '5m'
use_exit_signal = True
exit_profit_only = True
ignore_roi_if_entry_signal = False
However, because of my own methodology I will not follow his advice because otherwise I cannot compare the performance of this strategy with the earlier tests. But I will take notice of them when I decide to investigate this further if this proves to be a successful test.
Let’s continue with the indicators method.
Here the two sections of the BinHV and Clucmay strategy have been merged into one method.
Again , if you want to know what happens here, then please read my earlier blog posts or youtube videos for that.
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
# strategy BinHV45
mid, lower = bollinger_bands(dataframe['close'], window_size=40, num_of_std=2)
dataframe['lower'] = lower
dataframe['bbdelta'] = (mid - dataframe['lower']).abs()
dataframe['closedelta'] = (dataframe['close'] - dataframe['close'].shift()).abs()
dataframe['tail'] = (dataframe['close'] - dataframe['low']).abs()
# strategy ClucMay72018
bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
dataframe['bb_lowerband'] = bollinger['lower']
dataframe['bb_middleband'] = bollinger['mid']
dataframe['ema_slow'] = ta.EMA(dataframe, timeperiod=50)
dataframe['volume_mean_slow'] = dataframe['volume'].rolling(window=30).mean()
return dataframe
Then the buy and sell methods are determined. And it looks like the author will let the bot decide to buy if the BinHV parameters are met or if the Clucmay indicators are met.
So actually he has created a single strategy that actually reacts to two individual strategies. If one of these two has a complete signal, the bot will respond and do a buy of the pair in question.
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
( # strategy BinHV45
dataframe['lower'].shift().gt(0) &
dataframe['bbdelta'].gt(dataframe['close'] * 0.008) &
dataframe['closedelta'].gt(dataframe['close'] * 0.0175) &
dataframe['tail'].lt(dataframe['bbdelta'] * 0.25) &
dataframe['close'].lt(dataframe['lower'].shift()) &
dataframe['close'].le(dataframe['close'].shift())
) |
( # strategy ClucMay72018
(dataframe['close'] < dataframe['ema_slow']) &
(dataframe['close'] < 0.985 * dataframe['bb_lowerband']) &
(dataframe['volume'] < (dataframe['volume_mean_slow'].shift(1) * 20))
),
'enter_long'
] = 1
return dataframe
But for both of these buy signals, there is a single exit signal and that is where the candle closes above the bollinger’s middle band.
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
"""
dataframe.loc[
(dataframe['close'] > dataframe['bb_middleband']),
'exit_long'
] = 1
return dataframe
Interesting to see how the author has thought of combining two somewhat similar strategies, which both use the Bollinger bands.
Let’s see if this was just a lucky guess, an experiment or if there actually is a solid thought behind this algo strategy…
Initial backtest results
Considering the given that the BinHV performed moderate on the 30 minute timeframe and even bad on the 5 minute timeframe. And that the Clucmay also performed really poor with the initial settings but suddenly performed surprisingly well after optimizing the indicators, roi and stoploss. And this on the 5 minute timeframe. I could not really tell up front if how this strategy would perform initially.
Since both strategies performed bad right from the start I might have guessed that this combination would also perform poorly.
However I was pleasantly surprised to see that the combination of both two strategies actually performed quite well as you can see from these initial results. Now some parameters like ROI and stop loss are set differently from the other ones. But that is only a partial influence to these results.
Looking at the exit reasons, we can see that the exit signal is actually the main cause of all these profits. almost 8000 times an avarage profit of 1.5 percent adds nicely to your account.
However the stop loss does do a lot of damage to these nice profits. I can also see that there are twice as many stop loss signals than roi signals. So if I can improve the stop loss, maybe I can also improve the profitability of this strategy.
So why don’t I start an optimization on the ROI and stop loss settings,since there are no other buy and sell parameters to improve. And see what happens…
Hyperparameter optimizing
So after burning up my processor and memory. And not be able to use my computer for over a day I finally got some hyperparameter optimization results.
The things I will do for my viewers and supporters to keep them from shortening their computers lives is unbeleivable.
Just as the results after backtesting with these hyperoptimization results…
Because these results are unbeleivably bad…
over 7000 trades with a mere winrate of around 50 percent, while the amount of wins was originally 74 percent. Again pretty dissapointing to say the least.
Sure you can optimize Sortino, Calmar or Sharpe until they are infinite. But at some point you have to also look at all the other factors that determine the total algo strategies performance. And if you are satisfied with all these other numbers, then there is almost not much to optimize anymore.
And that is eventually the case with this strategy. Optimizing will not only lead to overoptimilization, but also curve / overfitting. Which is not realistic if you also want to use this algo in the future.
So I will use the original settings that the author has determined. I’m happy with his settings.
Plots
As with the Clucmay strategy. I am not able to open webpages with plots that are over ONE GIGABYTE large. If you have a PC with the capacity to show these plots. I will be happy to receive a screencapture of these so that I can add these to the post!
The strategy league
The league almost does not fit onto my screen nowadays. It’s getting pretty large, but not large enough though. Still lots to do.
Anyway, using the Cluc strategy portion in this strategy may be its saviour. And it is possible that the BinH portion makes it perform less good than the number one.
On the other hand, I can also say that the BinHv strategies performance is largely enhanced by adding the Clucmay part to its code. That’s a more optimistic approach.
But then again we would have two exactly the same strategies on the number one spot with different names though.
Nonetheless now we now that combination of different strategies is possible (but we already knew that already, did we). And also that combining strategies do not always create synergy.
But I am sure that I will come back to these words when a future combo of two strategies will get the first spot or so.
Files
Files are available in the patreon post I uploaded here: https://www.patreon.com/posts/81192000
I hope that you got something out of this post and I will see you the next time.