I'm 50, and have worked in tech my whole career, so here's my perspective. Generally though I agree with everything lisa13 has said!
I started out as an EE doing hardware design, the most male dominated field I can think of. I picked it because I was genuinely interested in electronics at the time - everyone told me I should be a lawyer. Study something that you'll like doing, not what you think you can make money at or where you won't face discrimination.
Eventually I did lose interest. Being an engineer at many companies means having to deliver miracles on someone else's schedule. I got tired of that and went back to school for an MBA. The combination of tech + business on a resume is a winner and it's not too difficult to find jobs that are challenging, interesting, and in some amazing locations.
Having said all that, I don't think Germany (I work for a German company in another country) is any better or worse than the US for ageism or sexism. I've worked in groups that were absolutely toxic to women (or "woman" since I was the only one), and others where it wasn't even a thing. It depends so much on the company, the team, the manager and you.
Anyway, don't plan a career around what might happen (or not) because you will never know what's coming next. Once I was picked to start a fast-track manager training, then a month later the company laid off our whole team. If things are bad in one group or even whole field you chose, try another. It's just a job, not your life.