In this article I will optimize and backtest the simple moving average crossover strategy for Bitcoin four hourly data. This is a part of a series. For the conceptual background of the simple average crossover strategy and the python code please read the first article in the series in which similar analyses are made for daily data. If you were a daytrader, how would you do using this strategy is the question we are attempting to answer. First, I will do the analyses for the period of January 1st 2012 – Math 6th 2021 four hourly historical price data for Bitcoin using Backtesting.py and optimize the moving average periods. Then I will use the backtest results to see how they performed in the last six months. I have to remind that this is an educational article, it is not investment or trading advice. Backtesting does not guarantee good performance.
Backtest Optimization Results
Let’s see which two numbers for short and long moving averages are maximizing our returns.
n1 n2
5 45 1.163926e+11
50 1.077298e+11
40 8.872312e+10
35 6.659061e+10
75 120 5.129846e+10
70 125 4.968772e+10
75 110 4.796958e+10
65 125 4.576299e+10
100 125 4.514021e+10
75 115 4.161445e+10
So the short period moving average is 5 x 4 hours and long one is 45 x 4 hours according to our backtest results, we will call this (5,45). Let’s visualize all possibilities with the heatmap. We are looking for the yellow zones.

So how do the actual results look like for (5,45):
Start 2011-12-31 08:00:00
End 2021-05-06 20:00:00
Duration 3414 days 12:00:00
Exposure Time [%] 58.801684
Equity Final [$] 116392592474.846054
Equity Peak [$] 135778333406.039246
Return [%] 11639159.247485
Buy & Hold Return [%] 1285717.539863
Return (Ann.) [%] 248.280608
Volatility (Ann.) [%] 223.452176
Sharpe Ratio 1.111113
Sortino Ratio 7.450375
Calmar Ratio 5.62726
Max. Drawdown [%] -44.121051
Avg. Drawdown [%] -4.404697
Max. Drawdown Duration 552 days 04:00:00
Avg. Drawdown Duration 10 days 22:00:00
# Trades 299
Win Rate [%] 37.123746
Best Trade [%] 431.999009
Worst Trade [%] -12.731801
Avg. Trade [%] 3.978347
Max. Trade Duration 64 days 04:00:00
Avg. Trade Duration 6 days 12:00:00
Profit Factor 4.49605
Expectancy [%] 6.249282
SQN 2.098167
Looks very well. 11,639,159%. 11.6 million percent, compare this to 1.3 million percent of buy and hold. When we traded daily we could only see 2,7 million percent returns. This time we were only exposed 58% of the time, reducing our risk. But look at our win rate it is only about 37%, could you have handled loosing 2 out of 3 trades you made? Only 299 trades in 3414 days, that’s less than one trade every 10 days. Could you wait that long if you were a day trader? But we surely curve fit, didn’t we? Let’s check to see if we did by using these parameters for the last 6 months.
Backtesting for the last six months
Let’s only look 6 months back this time. Not include the data before. Had we entered the Bitcoin market last year how would our optimized strategy perform, using (5,45) 4 hourly moving average crossover strategy.
Start 2020-11-01 00:00:00
End 2021-05-06 20:00:00
Duration 186 days 20:00:00
Exposure Time [%] 58.734403
Equity Final [$] 2339765.89792
Equity Peak [$] 2725753.44372
Return [%] 133.97659
Buy & Hold Return [%] 311.009521
Return (Ann.) [%] 425.505369
Volatility (Ann.) [%] 380.002016
Sharpe Ratio 1.119745
Sortino Ratio 11.424156
Calmar Ratio 12.828403
Max. Drawdown [%] -33.169006
Avg. Drawdown [%] -4.576993
Max. Drawdown Duration 54 days 00:00:00
Avg. Drawdown Duration 5 days 07:00:00
# Trades 15
Win Rate [%] 46.666667
Best Trade [%] 47.839314
Worst Trade [%] -7.163087
Avg. Trade [%] 5.840692
Max. Trade Duration 25 days 04:00:00
Avg. Trade Duration 7 days 04:00:00
Profit Factor 4.555034
Expectancy [%] 7.022421
SQN 1.351821
This time we are below buy and hold return almost by half, but our exposure time is 59% and we only made 15 trades and 46% are winning trades. This doesn’t look as amazing as the previous run does it? What if we optimized only for this period? The best parameters were 35 and 45. Here are the results.
Start 2020-11-01 00:00:00
End 2021-05-06 20:00:00
Duration 186 days 20:00:00
Exposure Time [%] 66.042781
Equity Final [$] 3276107.97572
Equity Peak [$] 3591007.73812
Return [%] 227.610798
Buy & Hold Return [%] 311.009521
Return (Ann.) [%] 913.708476
Volatility (Ann.) [%] 787.074086
Sharpe Ratio 1.160893
Sortino Ratio 22.345476
Calmar Ratio 39.27454
Max. Drawdown [%] -23.264651
Avg. Drawdown [%] -4.447675
Max. Drawdown Duration 31 days 08:00:00
Avg. Drawdown Duration 3 days 16:00:00
# Trades 12
Win Rate [%] 58.333333
Best Trade [%] 88.791025
Worst Trade [%] -6.881533
Avg. Trade [%] 10.427422
Max. Trade Duration 29 days 12:00:00
Avg. Trade Duration 10 days 03:00:00
Profit Factor 9.622808
Expectancy [%] 13.263011
SQN 1.624816
Better than the original optimization but we are still below buy and hold. And the top ten combinations are:
n1 n2
35 45 3.276108e+06
40 45 3.212561e+06
25 70 3.083995e+06
65 3.064522e+06
30 50 3.010306e+06
65 2.951431e+06
55 2.916412e+06
5 35 2.846912e+06
10 20 2.814127e+06
25 75 2.804406e+06
n1 = 5 and n= 70 is not even in the top 10. Also none of the strategies outperformed buy and hold returns. Let’s look at the heatmap.

Making Sense of Backtests
Similar to the results we obtained with daily Bitcoin simple moving average crossover backtest, for four hourly backtests we found that optimization is not an easily achived. It may or may not be better than a simple buy and hold. The strategy you develop may not necessarily be as successful in upcoming periods. Though I wonder finding n2 = 45 x 4 hour was a coincidence in both optimizations. You may want to continue reading the hourly backtest results in the series. Let me finish this again with the warning: this is not investment or trading advice.