Hello from another greybeard. I've been in the same boat. I'm not a programmer, though. I was a sysadmin and senior tech-support guy (L3, but I can do anything.) I never specialised: I do Windows, Linux, Mac, and in the past, I did UNIX™, VMS, Netware, all sorts of long-dead stuff back to CP/M.
In 2007, I decided to switch from freelance to an office job before I turned 40. It took me about 500 applications to get my first interview, over the phone. I landed the job on that first phone interview. It was good, reasonable contract rates, shift-based but I needed the money.
Snag: I used to be a journalist, and I preferred it. A journo job came up, so I quit. The journo job ended about 4 months later, just as the Credit Crunch hit.
Over the next 5 years, I applied for over three thousand jobs. Not exaggerating. I was British and I also applied for roles in any country where I spoke enough of the language to write the cover letter: France, Spain, Germany, Norway, Sweden.
I averaged one interview a year, I got 2 roles, one of which lasted 10 days and the other 2 months.
Ready to give up, I managed to get a book deal, which paid enough to pay off the urgent bills and cover a one-month intensive training course to be a Teacher of English as a Second or Other Language. I planned to go abroad and travel as a TESOL teacher, as I figured I was too old to work in IT ever again.
Well, I told a friend, and that got me a referral for a technical writer job at a Linux vendor – but in Central/Eastern Europe, the former Communist Bloc. I'd never considered there.
Well, that job didn't last, but I found another quickly and easily – in fact, I was offered 2 roles by 2 different companies.
I have had half a dozen jobs since then, steadily increasing my pay. I moved cities to the capital.
Now, as it happens, I am back to journalism, but what I would say to you is this:
Ageism is very real and it's rife across the English-speaking world and the West in general. Kids (and you know what I mean by that) will deny this, and point out that it's illegal, which it is, but it happens anyway.
There's no escaping it.
But I found that it's not true in the former Communist Bloc. I didn't make as much as I did in Britain, but then, the cost of living is about a quarter of the West, so I lived very comfortably, thank you.
I successfully rebooted my entire career in my late 40s and now in my mid-50s, I own my own place outright, I have a young family with an adorable tiny daughter, a fulfilling job, a savings account and some investments, and I don't owe anything to anyone.
Get out of the collapsing West. Go East. Not necessarily Eastern Europe, but a lot of the developing world is crying out for English-speaking experienced people.
Sure, there are remote jobs, too, but at local pay, which won't go far in the West.
Pre-COVID I flew back to visit my aging relatives 3-4 times a year, which is a lot more often than I could afford to do when I lived in another part of the same country.
Ageism is not a worldwide problem, but you will have to travel far to escape it. But it's totally worth doing, and I'm glad I did. I even changed citizenship to make it simpler.