This approach works - it's just a longer term algorithm. You will need patience, but over time, you will probably beat S&P 500 by a large margin.
Now, if you are looking for algorithms that trade 1000 times a day etc - forget it, or go find a job at an algorithmic trading shop.
Then you need to define a term. Eventually holding treasury bonds is likely to “beat” s&p. You just need to wait for the next big selloff.
And then there is no magic bullet nor free lunch. It’s all a big casino.
Anyone who assures you otherwise is not to be trusted.
Isn’t it what they teach in economics classes these days?