Mean Reverting or Trend Following? Find It Out With 2 Lines of Code - BTC and ETH

by Andrea Unger

Need More Help? Book Your FREE Strategy Session With Our Team Today!

We'll help you map out a plan to fix the problems in your trading and get you to the next level. Answer a few questions on our application and then choose a time that works for you.


Do you want to learn a quick and easy way to figure out a market's specific characteristics?

Then don't miss out on this video! We'll show you how to use TWO very simple lines of code to understand if a market responds well to trend-following or mean-reverting approaches.

This method works on any market, but in the examples given in this video, we've chosen to apply it to Bitcoin and Ethereum.

Enjoy! 😎


Hello everyone! One of the coaches at the Unger Academy here!

And today, we'll going to be showing you an approach that you can use to figure out the nature of a market in a quick and easy way.

In recent years, cryptocurrencies have acquired more and more importance. As systematic traders, we have applied the same methods that we already used on major futures to study these new instruments. But what are the first steps to figuring out the structure and nature of a market? And above all, what do we mean by 'nature' or 'behavior' of a market? Let's go and see it together! 

So, a possible way to learn more about a market that you want to trade, so to understand the behavior of the instrument that you're going to analyze, could be to move back and forth on the chart to figure out how the bars are configured. I immediately tell you that this isn't a good method since it's highly inefficient and not very effective. As systematic traders, we like to test our ideas and possible strategies to see how they behave over time.

In this video, we want to show you a very simple code that we generally use when we approach a market for the first time, so when we want to start trading a new underlying.

Breakout Approach

The script we are now going to see is extremely simple and contains only two lines of code. Let's see them together. We're going to write “buy next bar high stop” and “sellshort next bar low stop”, where 'sellshort' is the instruction to go short on an underlying.

These straightforward lines of code convey our intention to trade breakouts and, more in detail, to go long when the prices reach the highs of the previous day (because in this case, we are going to be using a daily timeframe) and to go short when the prices touch the lows of the previous day.

Now let's see what happens on Bitcoin by compiling the strategy on the BTCUSDT spot market. So we backtest the strategy on a historical series of data from about the beginning of 2017 until today and we use a fixed dollar amount. In this case, it's about $10,000, which means that the counter value of our position will always be equivalent to $10,000.

Let's take a look at the equity line we get by applying these two simple lines of code on a daily timeframe. As you can see, this equity line is extremely positive!

Both the short part and the long part produce good results. The fact that even the short part works - although not in an excellent way - may sound quite strange if you consider the fact that this market has always been rising over the years, so making some money with the short trades of a breakout strategy may not be that obvious. As for the long part, it's quite beautiful, and really, these results are truly amazing.

However, please keep in mind that this strategy, as it is written now, is not ready to be traded because there could be some errors during the backtest, such as double entries in the same bar, for example. So this strategy should be considered a super preliminary analysis tool that helps us understand if a market responds well to a breakout approach, like this one.

Reversal Approach

Now let's go and see how to test a market with a reversal approach. To do this, we can simply use the same code we've just used but replace stop orders with limit orders. So now, we will buy the next bar at the previous day's low with a limit order and sell the next bar at the previous day's high with a limit order.

Let's compile the strategy and see how it behaves on Bitcoin. This is a strategy that could work quite well on a stock market or stock index such as Mini S&P 500, for example.

Okay, as you can see, this approach doesn't work on Bitcoin. It loses money on both the long side and the short side. So it would seem that Bitcoin is a trend-following market, that is, a market that tends to rise when there is an uptrend, which means that it's more advantageous to buy on the highs and sell on the lows, rather than doing the opposite.

These two lines of code can be used to test all markets that you want.


So let's try it on another market... Ethereum, for example, which at the moment, is the second cryptocurrency by capitalization.

Let's take our reversal strategy, so the one we've just coded using limit orders, and look at the results. And even in this case, we don't find anything interesting.

So let's try and go back to the breakout strategy, so using stop orders instead of limit orders, and test it on Ethereum. Let's compile the strategy and see the results. Wow, the performances are remarkable in this case too! Now the strategy works very well on the long side, while on the short side, it seems to work a little bit worse than on Bitcoin, but still, it really works quite well and does make money. However, going short on this market quite often is not very effective.

Alright, so our analysis ends here. We have seen the characteristics of these markets, Bitcoin and Ethereum. And we've seen that breakout approaches work very well on them since they're definitely explosive, whereas mean-reverting logics don't work well at all in the medium to short term.

I really hope this video was helpful! If you have any questions that you'd like to ask, please write them in the comments! And if they're interesting, maybe we'll make some new videos based on them.

If you want to learn more about the world of systematic trading, I invite you to go and click on the link you're going to find in the description of this video. It'll take you to a completely free webinar in which Andrea Unger, the only 4-time world trading champion with real money, will introduce you to this world, which is so full of opportunities.

We'll see you soon in our next videos! And until then, bye-bye!


Need More Help? Book Your FREE Strategy Session With Our Team Today!

We’ll help you map out a plan to fix the problems in your trading and get you to the next level. Answer a few questions on our application and then choose a time that works for you.


Andrea Unger

Andrea Unger here and I help retail traders to improve their trading, scientifically. I went from being a cog in the machine in a multinational company to the only 4-Time World Trading Champion in a little more than 10 years.

I've been a professional trader since 2001 and in 2008 I became World Champion using just 4 automated trading systems. 

In 2015 I founded Unger Academy, where I teach my method of developing effecting trading strategies: a scientific, replicable and universal method, based on numbers and statistics, not hunches, which led me and my students to become Champions again and again.

Now I'm here to help you learn how to develop your own strategies, autonomously. This channel will help you improve your trading, know the markets better, and apply the scientific method to financial markets.

Becoming a trader is harder than you think, but if you have passion, will, and sufficient capital, you'll learn how to code and develop effective strategies, manage risk, and diversify a portfolio of trading systems to greatly improve your chances of becoming successful.