Algorithmic Trading: 20000 backtest iterations of a MTF SMA Strategy!


I hope this post inspires the start of a systematic trading research group.

We attempt to optimize a simple trading strategy. This exercise highlights the severe limitations and access to robust quantitative systems for JUP ecosystem members due to hardware requirements and the coding difficulty required to conduct efficient data analysis for trading.

If you had a 60% winrate strategy with 2:1 risk reward on the 5min timeframe, would you share this knowledge, how much would you charge? - of course “they” wouldn’t share that for free, as infinitely profitable as that may seem, it is infinitely expensive to mine and maintain!

The Strategy:

  1. The strategy is multi-timeframe and trend following using a fast and slow sma as an indication of the trend.
  2. A Bullish trend is when the fast sma if above the slow sma, and vice versa.
  3. Our entry is defined when we have a bullish trend and the close price crosses above the fast sma, as seen below:

The optimization parameters:

We will be using multiple parameters for SMA lengths and timeframes. The strategy is only allowed one position at a time, and we will be enforcing a hard stoploss and take profit rule.

timeframe_freq_values = [“1H”, “4H”]
fast_ma_freq_values = [“1H”, “4H”, “D”, “W”]
slow_ma_freq_values = [“1H”, “4H”, “D”, “W”]
fast_ma_length_values = [10, 20, 50, 100, 200]
slow_ma_length_values = [10, 20, 50, 100, 200]
tp_values = [1.02, 1.04, 1.06, 1.08, 1.1]
sl_values = [0.98, 0.96, 0.94, 0.92, 0.9]

The product of which results in 20 000 iterations of a backtest function! This is a far cry from the level of research we need to beat our centralized counterparts, with no guarantee of success :frowning:.

Adding just two more parameters and we reach a staggering 200 000 iterations!


We have filtered the results to return strategies that provide:

  • 10x on initial equity;
  • positive risk reward ratio; and
  • greater than 50% win rate.

We end up with only 14 variations out of 20 000:

Lets visualize a selected strategy (last 250 bars):
Timeframe: 4H
Moving Average: 4 Hour 20period as fast sma & Daily 10 period as slow sma
TP: 10%; SL: 6%

Winrate: 51.94%
Amount of trades: 129
Culmulative pnl: 298.0% *idk stats much, but this the sum of pct gains per trade and probably not the right name.
Max drawdown: -10.000000000000014 % (negative never in drawdown)
Equity Max: 12800.79 USD
Equity Min: 1100.0 USD
Final equity value: 12800.79 USD
Summary: $11800.79 profit made from $1000 initial in about 2380 days 00:00:00 hours & minutes


The provisional signs looks promising but the MTF Moving average trading strategy requires further observation.

For further observation:

  • Sell only backtest needs to be completed, BTC is long biased.
  • A tweak to the entry signal to include lows and not only closes.
  • The strategy appears to be suitable for leverage, displays very low drawdown.

Results of the further observations coming soon. Please post your own observations or what you would like to see below! Peace :man_mechanic:


I enjoy reading these, my main observation with this specific strategy is we don’t beat buying and holding BTC during the same time period.

Have you attempted any strategies that can beat buying and holding BTC? Have you attempted any lower timeframe strategies?


Hi @BTC !

Currently running a similar backtest with lower timeframes and more parameters. I have no idea how long it will take to complete as the elapsed time is over 24 hours already, but I estimated between 4-6 days to complete the optimization. (For comparison the 20000 iterations backtest took about 7 hours).

I appreciate the feedback I think you made an excellent point. FYI in the backtest above there were many that beat the final equity of buy and hold some greater than S22,000.00, I purposefully did not select those because final equity ignores many other key factors. Allow me to explain:

The trading bot used $1,000 as a base investment, lets say you purchased in the very first row of the data and sold at the last:

Buy $1,000 of BTC @ $4,326.23 receive 0.2312 BTC to receive,
Sell the 0.2312 BTC @ $66,837.19 to receive 15,499.29 USD
(again this is very unlikely that you bought the bottom and sold the top but we will give it to you 'coz you are a cool catdet like that.)

Exposure time:

Arguably the biggest factor since the algo is not always in the trade - admittedly, I cannot show this with my backtest and I will look to include it in the future (thank you again for bringing this up).

Buy and hold requires 100% exposure time, and there is an inherent risk in this: the drawdown is held over long periods of time. You cannot allocate the funds elsewhere because you might miss the pump, and so you also miss out on opportunities to make more money, e.g in another algo bot.


Do I need to say more? Let us assume you were not so lucky to buy the absolute bottom, imagine keeping your BTC at 70% down for a period of three years, only for it to get to break even all whilst it was not earning you anything.

Underdiscussed but the emotions of retail traders are a real deal.

The real reason:

Due to the lower exposure times and low drawdowns, the strategy is eligible for increase in position size if you know what I mean - 100x nudge nudge cough cough - but seriously, with the includion of a market exit and entry you could use 10x leverage in which case the cumulative pnl and final equity would increase by the amount of x’s :slight_smile:

Another reason:

It trades automatically but also… this was only one direction, what about the gains made on the short side. Keep an eye out for that soon.

Hope that answers the question, lets speak again soon!

1 Like