Learn math. Learn physics. Learn some chemistry or biology. Be able to write digital signal processing code. Know linear algebra. Learn some NLP. Learn enough algorithms to write an efficient soldering path tool, or network router. Even there I am not sure of the moat; the number of searches for terms like "asymptotic complexity" are far higher in places like India and China than the US. But if you can reasonably say "if I leave it will take 3 normal people to replace me" you will have job security and the ability to command a high salary regardless of the economy.
Secondarily, I think there is an untapped market for people that are actually able to architect software and lead teams. I don't mean writing StrategyFactoryAbstractVistorBuilderFactorySingletonFlyweight horror shows, but actually putting together a solution that is maintainable and extensible over time. The field seems very immature in this regard. Or someone that can just think clearly, put a plan together, and execute it, even just at a middling level, seems pretty rare. I don't know if that (project management) pays a lot, but I think skilled people are worth their weight in gold. It seems to attract people that don't have the technical chops, not because they chose a different education, but more that they tried to be technical and just weren't that smart. If you are smart, you will always have a job in that arena.