The ASDTRockwell trading strategy (Patreon)
Content
Introduction
- NOTE: THIS IS A REPOST BECAUSE I AM MOVING ALL MY STUFF TO PATREON -
Hi there, and welcome to another post on this website.
As you might have noticed the last post about testing a trading strategy was quite a while ago. Not that I wasn’t busy though… I was primarily focusing on the Creating a trading bot video, setting up my new Patreon place with monthtly subscription type and recalibrating my strategy league with the dataset over 2022. These three subjects took so much time (besides my normal day job and family life – not to mention the holiday season) that I did not had the additional energy to also do the strategy testing videos.
But now things are getting somewhat back to normal. So therefore I will take up the challenge again to test as many trading strategies as possible to see if they are profitable and have the probability to also make money in the future (note that past results do not guarantee profits in the future!).
Nonetheless it is a good exercise to do because it not only gives insights into other peoples algotrading ideas, but also provide good coding examples that you can use in your own algo trading strategy ideas.
For the upcoming algo trading strategy blog posts and related Youtube video’s I also have decided to be a little bit more opportunistic and take the ‘low hanging fruits (strategies)’ first.
As you might know, the Freqtrade github repository already has loads of strategies and I already have tested some of these in the past. However I get the impression that some of them are not more than a simple example with some simple buy and sell rules based on the status of an indicator (or two). And some files are fairly complex and an actual serious attempt to create a winning strategy.
At some point I will be testing these strategies anyways and that is why I thought to myself, why not do these first and then continue with some more complex ones that are also based on other Youtube videos. I’ll have to code these by myself anyways and it is better to get the experience and examples from already available code anyway.
The ASDTRockwell trading strategy
So therefore let me start with the first strategy file that is in this list (which I did not already test), and that is the ASDTRockwell trading strategy. Created by Gert Wohlgemuth.
It is a strategy that originates from a Youtube video that is not available anymore unfortunately.
But the idea of this trading strategy is well explained in the code and is very simple to grasp.
Buy and sell settings
This strategy code is based on spot trading and has the following buy and sell settings:
The idea is literally to buy an asset when the MACD line is above the MACD signal line AND also above the 0 line.
To sell the position, the MACD line should get below the MACD signal line.
Besides these buy and sell parameters there are also the ROI and Stoploss settings that are always included in the Freqtrade strategy code.
# Minimal ROI designed for the strategy.
# This attribute will be overridden if the config file contains "minimal_roi"
minimal_roi = {
"60": 0.01,
"30": 0.03,
"20": 0.04,
"0": 0.05
}
# Optimal stoploss designed for the strategy
# This attribute will be overridden if the config file contains "stoploss"
stoploss = -0.3
# Optimal timeframe for the strategy
timeframe = '5m'
The ROI take profit points are divided by multiple time settings and the position will be sold if after set amount of time a certain percentage is gained.
The stoploss setting is set to sell when the position has a 30% loss after the initial buy.
And finally the strategy is initially set to work best on the 5 minute timeframe. But we will see later if this is actually the best timeframe after backtesting this.
Indicator section
In the indicator section you can see that only the MACD indicator from the TA-LIB module is loaded. There are no additional parameters here so the default MACD settings will be used in this strategy.
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
macd = ta.MACD(dataframe)
dataframe['macd'] = macd['macd']
dataframe['macdsignal'] = macd['macdsignal']
dataframe['macdhist'] = macd['macdhist']
return dataframe
These default settings for MACD are:
- Fast line: 12 period EMA
- Slow line: 26 period EMA
- Signal line: 9 period EMA of the MACD line
And as you might already know, the MACD line itself is the fast line minus the slow line.
Buy and sell signals
The final piece of code signals when the bot has to buy and when to sell. Is consists of some simple Python statements as you can see below:
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Based on TA indicators, populates the buy signal for the given dataframe
:param dataframe: DataFrame
:return: DataFrame with buy column
"""
dataframe.loc[
(
(dataframe['macd'] > 0) &
(dataframe['macd'] > dataframe['macdsignal'])
),
'enter_long'] = 1
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Based on TA indicators, populates the sell signal for the given dataframe
:param dataframe: DataFrame
:return: DataFrame with buy column
"""
dataframe.loc[
(
(dataframe['macd'] < dataframe['macdsignal'])
),
'exit_long'] = 1
return dataframe
Initial backtest results
The initial backtests that I always do is to test this strategy over a dataset with a time period of starting in 2017 until the start of 2023. I have an extensive post on my Patreon page where I explain in detail how I updated the complete backtesting dataset and also which pairs I will test in the coming year. So if you want to know more about this setup and also how to setup your complete environment to do these kinds of backtests also, then become a member of my Patreon page to get additional information and benefits around this subject.
The usual procedure to do initial backtests is to see if the proposed timeframe that is in the strategy is actually the timeframe that works the best. If another timeframe gives better results, than that is the timeframe I will use for further improvements and analysis of this strategy.
I also have created additional scripts that help me to execute the exact same command for each timeframe so that I do not get results I cannot compare.
After testing the ASDTRockwell strategy over multiple timeframes I have the following results:
And as you can see in this table, over all the time periods tested the 1 day timeframe has the best results. It is also the only timeframe that has a positive end result. All other timeframes, inclusive the 5 minute timeframe proved to be losing over the tested timeperiod.
Looking at the exit reasons of this strategy, I can see that the exit signal (besides the stoploss) is the main reason why this strategy does not perform great.
===================================================== EXIT REASON STATS =====================================================
| Exit Reason | Exits | Win Draws Loss Win% | Avg Profit % | Cum Profit % | Tot Profit USDT | Tot Profit % |
|---------------+---------+--------------------------+----------------+----------------+-------------------+----------------|
| roi | 3191 | 3191 0 0 100 | 3.02 | 9631.31 | 14430.3 | 963.13 |
| exit_signal | 643 | 6 0 637 0.9 | -10.5 | -6753.92 | -9968.13 | -675.39 |
| stop_loss | 80 | 0 0 80 0 | -30.09 | -2407.06 | -4282.49 | -240.71 |
Every time a bearish crossover of the MACD occurs (MACD < MACDSIGNAL) an exit signal is given according to the strategy. But in reality this occurs very often when the trade already is in a losing position. In this specific case only 6 times did this crossover occur when the strategy was still in a profitable position.
Since ROI is the main reason for exiting a trade with a profit, it is interesting to find out if these settings can be optimized further so that this strategy can be more profitable.
Hyperparameter optimization
The original code of this strategy does not have indicators that can be further optimized. The original MACD parameters in the code are default and I could change the code to make them optimizable. The strategy itself is not that different from earlier strategies that also use the MACD indicator as a primary or secondary control indicator so If I wanted I could use those already optimized parameters instead.
Personally I do not think it will not make this strategy any better than it already is. It has more change to attain a curve fitted bias, which may not fit future market circumstances. Especially if you know that many people are making use of the MACD with its default values to base their trading decisions on.
I think that optimizing take profit points based on the ROI and stop loss parameters will have greater changes to create a strategy that might be profitable in the future. But no guarantees of course.
So when I optimized the settings for ROI and stop loss, I get the following results:
Suddenly this strategy became much more profitable than before. To see what happened we have to look at the exit reasons again?
===================================================== EXIT REASON STATS =====================================================
| Exit Reason | Exits | Win Draws Loss Win% | Avg Profit % | Cum Profit % | Tot Profit USDT | Tot Profit % |
|---------------+---------+--------------------------+----------------+----------------+-------------------+----------------|
| stop_loss | 1913 | 0 0 1913 0 | -4.13 | -7892.14 | -66005.2 | -789.21 |
| exit_signal | 361 | 271 0 90 75.1 | 4.59 | 1657.3 | 11158.7 | 165.73 |
| roi | 203 | 203 0 0 100 | 49.62 | 10072.2 | 69106.5 | 1007.22 |
After optimizing the parameters, the stoploss setting went from a 30% to 4%. This means that trades are quickly stopped out when they proved to be bad. You can see that from the average negative profit of -4.13%.
The second thing is that the exit signal and ROI setting are now much more profitable then before. In this case the strategy became more of a "let your winners run" kind of strategy. No quick profits are taken with tight ROI settings like before, but instead letting the MACD exit signal decide when to stop a trade. Also the ROI settings are much wider than earlier, which means that there are lesser but more profitable trades to be made.
All output of this test will be placed on my Patreon account so if you want to see the output and test these results on your own machine, then please become a supporter to attain these files.
Strategy League
So where does this relatively simple algo strategy enter in the strategy league:
With it’s adjusted ROI and stop loss settings, this strategy enters on the 9th spot in the strategy league. This mainly due to the relative low drawdown and high Calmar, Sortino and Sharpe ratio in comparison to the lower scoring strategies.
For a trend trading strategy like this, it typical to let your winners run and cut your losers strategy. That is why the winrate is on the lower side. Nonetheless, this proves somewhat why the MACD is such a popular indicator. It is simple and effective and with the right TP and SL settings you have the potential to have future winning trades.
Files
All files are available on my Patreon page so if you are not already a supporter, then please become one!