In this post I’m trying to reproduce a strategy that was recently uploaded and has much attention on Youtube. The strategy is called RSI Cobra and according to the Youtube statistics it is very popular. So let’s jump on the popularity bandwagon and explore this trading strategies results on Cryptocurrency trading.
So as I said in the intro of this video. This algorithm has a tremendous popularity and has 23k views at the moment of creating this video. So there should be something that makes this algo extremely popular within the trading community.
I will get straight to the point and will just start with the indicators and trading signals that are mentioned in the video.
According to the video this strategy should be fit for Cryptocurrency and it makes use of a couple of very simple indicators:
Something that indicates a inclining or declining trend.
A couple of simple moving averages that together form a banded simple moving average. Comparable with the Bollinger Bands or Keltner bands.
The center of the band is the 50 day simple moving average, calculated on the close price of the candles. The upper band is calculated as the simple moving average but here it uses the high price of the candles. And for the lower band the simple moving average of the low price of the candles is used.
Why it is called the Cobra is not mentioned in the video but it sounds cool. So why not.
Furthermore the 14 day RSI indicator is used
And an 50 day moving average on this RSI indicator
According to the original video the rules of entry and exit are as follows:
The price should be upward sloping for longs and downward sloping for shorts
Price is rising and should be above the Cobra moving average for longs or the close price is below this cobra band for shorts.
The RSI's 50 SMA should be above the 50 level for longs and below the 50 level for short trades.
The RSI 14 should also be above 50 for longs and below 50 for shorts.
The real signal for longs is when the RSI dip below its 50 SMA and then goes above it again. Then we open a trade at the next candle after this cross.
To go short the RSI should get above its 50 SMA first and then dip below it again for the trading signal to go short.
The stop loss is set below the last swing low for longs or above the last swing high for shorts
But as for the sell levels, these are not explained as far as I could analyze the video. For some reason these were always indicated at the next highest or lowest swing levels. Also the R:R is unknown in this video.
Also there is no scenario proposed where the take profit is never hit but all the original signals for entering a trade stop signalling. This is what I call “trade signal lost” by the way…
So for some of these rules I had to make some assumptions and add my own custom rules. But not much. Most of the original rules were kept.
Coding into an algorithm
I first started to code these trading rules into a trading algorithm in a Jupyter notebook.
From there I could test out the correctness of the signals.
The first thing I did is to create a pandas dataframe so that I can add my trading signals to it.
The next thing to do is add the indicators like the RSI, Rsi’s moving average, and a couple of simple moving averages to create this Cobra band.
Then I asked ChatGPT to create me a function where stop loss and take profit points are determined. Since the strategy does not have exit signals based on the used indicators for entry signals.
So eventually I ended up with this function to determine the entry and exit signals based on the initial entries. Now since there is no data given on the risk to reward level for this strategy, I assume a Risk Reward setting of 1 to 2. So I risk 1 dollar for 2 dollars gain. Hopefully that will be enough to get some good returns based on the risk we take. I coded this into the stoploss function to have more flexibility choosing the right R and R settings.
Now since the first rule of the trading algorithm is to determine if a market is rising or falling, I had to come up with some sort of indicator to detect this. Eventually I chose to use a linear regression indicator to determine this.
Then there is the thing where RSI crossing above or below its moving average has to be detected for entering a long or short trade. For this I had to revert to the following function where crosses can be detected.
I also created a bunch of counters to see which subset of signal parameters provides which amount of signals. In this case we should look for a balanced amount of high quality signals that can get us into trades that provide us with positive returns.
Now these counters only show the amount of signals created for long trades only. And only on the BTC USDT pair. Over the dataset I used for this dataframe, you see that I only have 24 long signals if I use all the parameters for at trading signal. If I leave the RSI cross above its SMA out of the equation, then I suddenly have 524 signals. At first I thought that this was an indication on how well the RSI cross filters trades to hopefully get the highest quality signals.
But eventually I deviated a little bit from the strategy because instead of a cross over or down I will let the algorithm enter the trade if the RSI is just above its SMA. And not exactly at the cross since these can occur at moments where the other signals are not there. But they happen one day before or after the cross occurred. And that would lead to a missed signal.
So with this knowledge I coded this into a Python file that is also useable with the backtesting engine of Freqtrade. Let’s backtest this trading strategy to see if it comes close to that claim of 98 percent accuracy.
I backtested this strategy with two different files. One there I only do spot trading and one where I do futures trading.
Futures results original strategy
The results you see on the screen here come from the tests on futures trading where you go long and short. These results should reflect the original strategy most since long and short signals are proposed.
And I must say that I am somewhat surprised and disappointed at the same time as well. Because it seems that this trading strategy indeed made a hypothetical gain over the backtest data of over 3500 percent. But the disappointment comes from the given data that not a single indicator has a 98 percent accuracy. It’s far from that actually…
Now of course the first thing that comes into my mind is the possibility of a coding error or the fact that some crucial missing information I had to do an educated guess on trading rules. Besides my own decision to do only trades above the RSI Moving average and not the exact crossover. But I never thought that this could be of such influence that the numbers you see here are not even close to 98 percent is surprising to say the least.
As for the weekly performance, we can see clearly that this strategy really gets bashed when bear market circumstances arise. The strategy does not make the best use of its abilities to enter shorts when markets go lower. Although I cannot say how the spot only version will perform yet. My current impression is that the stop loss gets hit more often than intended and therefore causes more losses than wins. So I tested with other settings to see if these proved to be more optimized, but unfortunately that was not the case. Som ore investigation is certainly needed here.
The influence of the bad performance also has its impact on the drawdown, that at some point had a maximum of almost 50 percent.
The plot on the left shows the distribution of win rates for a trading strategy. The median is around 40 percent, with the interquartile range (IQR) between 20 and 60 percent. There are some outliers, with a maximum at 1.0. So the strategy has moderate success, with occasional perfect runs but more often hovers around a 40% success rate. Which was visible in the table.
The right plot displays the profit distribution. The median profit is slightly negative, with the IQR spanning between around -1000 and +1000. There are several outliers, extending profits up to over 10,000. You tell by this that the strategy is somewhat inconsistent, with a winrate around 40%, occasional strong profits, but mostly modest gains or losses. And this can be the cause of the tight stop loss setting as a result of the last lowest swing candle setting as the stop loss in the strategy.
Spot results original strategy
The test where only spot trades are allowed show the following backtest results over the timeframes I usually test.
Again it’s almost the same picture here. No number ever reaches the 98 percent mark. Just like the futures trading version it does make money but at the expense of your nerves because a drawdown of 48 percent and a maximum lose streak of 33 losses after another is a nail biting experience.
The equity curve here looks even worse than the futures version. But for some reason spot trading only causes a higher peak to about 10.000 usdt profits and with the drawdown still ends higher in this backtest experiment. Still this is not the curve I get exited about though.
You might have guessed the drawdown plot here too. Some sharp peaks that get higher where the bear market proceeds further
The box plots always tell an interesting thing about the nature of the trades.
In this case the median winrate is around 30 percent, slightly lower than the previous plot, indicating this strategy wins less often.
The central range (IQR) is between 20 and 40 percent, which shows that most weeks have a low winrate. Nonetheless, there are also outliers at 100 percent And this indicates a few highly successful weeks with nearly all trades being profitable. These highly successful weeks might explain the steep peak in the equity curve.
Unfortunately the median profit is near zero, and this indicates that over time, the strategy neither consistently gains nor loses much money. And the interquartile range (IQR) is tightly packed between -1000 and 1000, which suggests that most weeks see small profits or losses.
So if I compare these boxes with those of the futures trading version then this strategy performs less consistently than the previous one in terms of winrate, with most weeks hovering around a 30% success rate. But the rare, highly profitable weeks might be the cause that this version eventually ends up with a higher end balance . And the risk of occasional large losses is also present here too.
Conclusion and Ending
So what should we conclude after doing a backtest of this trading strategy?
Well considering this is a test on my personal setup and there is no way of telling what or how the original video uploader came to his conclusions of 98 percent accuracy I can only tell you something about my personal results.
I admit I’m a little bit jealous on the amount of subscribers, views and feedback this youtuber has on his trading video’s. Considering there is no way to verify and confirm the findings that are presented. I hope I could ever reach that audience with my humble set of video’s but I also realise that .
I tried to stay as closely as possible to the original strategy and I think I came pretty close to that.
But eventually the endresults count and both these tests show that the proposed strategy only has mediocre returns in comparison to the other algorithms I tested so far.
While the end score of the futures trading version is a little bit higher than that of the spot trading one because of its better risk management abilities, I still believe that this proposed strategy lacks certain higher level risk management features or specific setting to improve this.
But since the original poster of the video is not clear on these other trading rules or shows any real results on which he claimes the 98 percent accuracy, we probably have to find out ourselves where and how we can tweak this strategy for better performances. For me at least I learned a lot coding this strategy and have gained some new tools for future algorithms.
And with this end conclusion I am at the end of this post. Thanks for supporting me and I’ll see you in the next one.
Goodbye!
teziroct
2024-10-07 21:29:02 +0000 UTC