Counter example: I lead a software team doing new product development for a multi billion company NOT in the valley. Plenty of my engineering coworkers are grandparents. They are very much comfortably employed.
My boss is 50ish, young at heart and a brilliant software architect. He still gets actively recruited and has no end of companies approaching him for contracting gigs outside of work.
Find a niche and stay effective. You'll probably be employable forever.
Well, one man's established company and non-hipster framework is another man's cave and commodore 64.
I've personally experienced a glaring cultural and technical difference between work environments in the SF/Seattle areas and ones in other technology hotspots - even within the same company.
I'd be interested to hear about these if you had the time.
One of the most important words in the OP's sentence is 'mediocre.' Of course great engineers will be in demand, regardless of age. But the big push towards CS education today is going to bear fruit in 10 years, at which point, wages and opportunities for older, less talented workers will decline.
I'm seeing this already among my older peer group. Even in a what is seen to be a tight job market, they are having to interview much, much more often to get even one offer.
Software engineers are in this really sweet spot. They are a scarce high-skill asset and if you aren't pulling in above industry average wages you should be hopping to the next job that will pay you more.