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.
I am basically learning algorithmic trading. I know it’s really hard and if someone finds something profitable they probably wouldn’t share it but it’s very motivational if you find something that beats the market even by a small margin.
Still, I personally wouldn't share it had I had one, since generally the more traders use it the less effective it gets.
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.
I had a college roomate who gambled with his student loans in the stock market.
He tried to convince me to invest a few weeks before COVID tanked the market. He even questioned me why I was waiting to pull the trigger.
Isn’t it what they teach in economics classes these days?