I defended my alcoholic dad for a long time, I used to get upset thinking that he was all alone with no one to take care of him when we were at our mom's house. He was very manipulative, just like your ex.
I think I was scared of upsetting him because on some level I knew that his love was conditional, based on me being a compliant, perfect child. It was "safer" to take things out on my mom because she was pretty much always there.
I'm glad your daughter has you in her corner to protect her, even if she doesn't appreciate it now, you are definitely doing the right things. Be patient with yourself and with her.