I'm not sure if I'm making poor decisions when choosing companies.
(early 40s tech guy here, currently working for big tech in a major metro. comp was in the $100k range in the mid 2000s at smaller tech companies, then went to $500k in the 2010s at big tech, now about $1.2m as a senior manager, still in big tech.)
The general way to get ahead in tech is to put yourself in the deepest pool possible and have no work-life balance, while relentlessly climbing inside the company you are in. While doing this, always be looking around and leveraging what you have into something potentially better - there is a shortage of software devs in the world, so you can usually level up on comp if it's really important to you.
The reason I pulled that quote of yours from above is that the key to maximizing your growth and comp in tech is to make sure you're in the right companies. This means tech-focused places where engineering drives the company. If you're a great dev at an insurance company, you will almost never do as well as if you're at an eng-focused company.
The other challenge for you is where you live. Your earnings are hard-capped in many parts of the US, but you also likely have a higher quality of life for it.
What this all comes back to is deciding what tradeoffs you want: if you want your earnings to go up, figure out how to get hired at a FAANG. If you want personal growth, find a place where you feel like the dumbest person in the room. Are you willing to move for it? Are you willing to take a year at (maybe) lower earnings to build your skillset? Are you willing to spend your nights and/or weekends getting better at something?
The one part of what you're saying that I don't buy much is the age side of it. I work with plenty of people who kill themselves to get ahead and earn a lot of money in the process. Some of them are 30, some are 40, and some are 50. In my experience, when someone says "I'm worried that company X won't hire someone who is 50", the unstated part is that a lot of 50 year olds don't want to work the extra hours and/or the stress that comes with the higher-paying jobs. Those who do fit in just fine. (As an aside: I'm not saying any of this is good/healthy, but in the late-stage-capitalism hellscape that corporate America is, it's what you get.)