I've never switched jobs to make more money. In every situation where I switched a job my current employer was willing to match my offer. I will switch jobs to work with smarter people, to work on more interesting problems, to work with newer technologies, or to fight boredom. In theory I would switch to a job with lower pay to satisfy other requirements but luckily I never had to do so.
I don't think there's much to the professional athlete analogy. There is virtually no "demand" for more professional athletes while the demand for good software developers is ever growing and is unlikely to show any sign of slowing down. There are cycles but the trend is up. It is also really hard to be a good software developer and requires a combination of aptitude and attitude.
I work for a US startup and I know we do not discriminate by age (if anything older developers are over-represented). In companies like Google, Microsoft, Apple, more experienced developers (in their 40s and 50s) are pretty well represented (keep in mind that as you go back in time the % developers is naturally less simply because the industry was much much smaller). Saying that I realize that in some places simply being a bit older would be seen as a poor fit and definitely someone who is just starting to code in their 50s is not going to be looked at the same as someone out of MIT.
Another thing to realize is that software development is an immensely wide field. I think your advice is reasonable for someone who has only started writing code in school, works in relatively "easy" areas where a lot of expertise isn't required, is really in it for the money and approaches things with that sort of cold success driven attitude. People who have talent, go deep into their fields of study and are highly motivated are probably looking at a much longer successful career. [EDIT: In other words it depends on what types of software you work on, your abilities and passion, and your further ability to maintain your abilities and passion and expand your knowledge.]
That said there's absolutely no way to project what the world economy or job market will look like 20 years from today. There are likely to be pretty big changes. One can imagine a much larger % of the population working remotely. One can imagine some breakthroughs related to aging that will make the entire age issue moot. Who knows. My advice to juniors is to strive to be the best at what you do. If you're the best you'll always have a job. Professional athletes don't always stop working when they're 30-something, they can become a higher paid coach. They can work on TV. Lots of options. By the way the average age of athletes has also been creeping up.