Trend Following Algo Building Series - Part 4
Generating live signals; Making changes and backtesting again.
This is Part 4 of the Trend following algorithm building series.
The purpose is to show how it’s possible to create an actual profitable trading algorithm, by doing a bit of research and following some simple steps.
No advance math needed.
Here are the quick links to earlier posts: Part 1, 2, and 3.
In this post, we’re checking the live signals, making some adjustments to find the 2 sets of parameters to live test, and go ahead with live testing toward the end.
There’s no time to waste. Let’s go.
Alright. So I spun up the signal generator since Jan 6.
Today is Jan 13.
One week of data is not enough to go live for real.
However, I’m merely looking to see that the signal is generated properly.
Here’s my recent tweet on the results:
I didn’t like that the 3 signals were producing near identical results.
I wanted to compare the methods and eliminate as much as I can from further testing.
Recall that in Part 3, I proposed to have 3 methods for identifying what trend BTC is in, and couple that with a super simple entry and exit criteria.
It occurred to me that I hadn’t test the look-back period & threshold.
Also, I might as well as test the other parameters (timeframe and stop loss).
OK.
Time to go back and do a more thorough backtest sweep of those parameters.
Testing and dropping lookback and threshold
My first test is to see for what lookback and threshold values can I use to improve the backtesting results of Method 2: SMA Flip w/ Threshold, without too much optimization.
To test lookback, I’ll need to fix these as constants:
Daily timeframe
SMA(32)
Threshold of 0.05
Stop loss of 1%
I tested lookback values of 3 to 50 periods (to calculate the standard deviation).
Seems as though the lookback factor didn’t matter at all.
Values of 3 to 30 yielded the same result. And drops off after 30.
I then held the lookback constant and tested the threshold values.
The best performing threshold from that backtest ranged from 0.02 to 0.05.
Overall, since I’m getting the feeling that lookback & threshold aren’t important enough to materially affect PnL (profitability) on their own, so
I’m going to drop lookback and threshold as variables to care about.
This means, I’m abandoning the SMA “Flip” with Threshold signal altogether!
Awesome.
Testing for a suitable stop loss to use
Next, I’m going to test out stop loss to see if I can find good performing ranges.
I’ll test a super wide range from 0.1% to 40%.
The best performing range came in at 0.7% to 1.4% as well as 2% to 2.6%.
Great. Seems I can more or less fix the stop loss.
We’re not done. After testing for the remaining timeframes, we’ll once again revisit stop loss testing to find the most promising values. touse.
Before going further, there’s another worthy consideration — whether we take both long and short positions (two-way) v.s. long only.
Since BTC historically has a strong up bias, the intuition is to go with long only. However, backtesting suggested otherwise - that there’s still plenty of room to capture profits going both ways (long and short).
Testing for timeframe
Based on my research, most successful traders recommend using a high timeframe (1 day or more). I wanted to be thorough and rule out any lower timeframes that could potentially product more frequent signals. And if it turns out that I can find good profitable ranges for our parameters, we can turn this in to our “B(eta)” strategy.
So we’re clear — the “A(lpha)” strategy would be on a larger timeframe than the “B(eta)”.
Timeframes being considered are:
High — 1w, 1d
Medium — 12h, 6h, 4h, 2h, 1h
For 1 week (1w), it was quite difficult to lose money, with only 6 out of 46 SMA periods tested that lost.
Yet, the max ROI was less than ones I found using the 1d timeframe. Furthermore, with 1w timeframe, SMA “Flip” performed better than Heikin Ashi (HA).
For 1h timeframe, going both ways is absolute trash. Long-only worked better. Also, HA performed noticeably better than SMA “Flip”.
2h timeframe looks a lot better than 1h, with decent returns for SMA 30 and above, by going long-only. HA performed slightly better than Flip.
4h timeframe is not too different than 2h, performing actually a little worse. Again, HA performed better than Flip.
6h timeframe performed better that 4h. HA performed better than Flip.
12h timeframe performed drastically better than 4h and 6h. HA performed just as well as Flip.
Phew.
I know this section is deadass dry.
But it’s necessary to increase our odds of finding profitability.
If you’re still reading, I think you definitely have what it takes to find profitability like I did.
🦉
Let’s wrap this up.
Armed with the above backtesting data,
I’m going ahead to implement the Execution part of the strategy (i.e. actually making trades when it detects the right signal).
Next time, I’ll be reporting back on how well live tests perform with real money!
Can’t wait to see how it performs (or how it fails).
See ya in a few!