What you can do is do a lot of no stirrups exercises like just posting without stirrups will help build strength in your lower leg and will get your leg to stay put while riding. Also make sure your heel is always down that will also help you!
Keep a raised seat in a grid and focus on pushing all your weight into your heels and not let your legs swing - also can try the grid with no stirrups!
My trainer always had the most quiet let that never moved and she said that she grips with her lower calf where there isn’t any muscle
I had the same problem, but now it isn't difficult for me :D I'm trying to put my weight on the stirrups and loosen my legs.
I hope I helped you :)
You can try to work without your stirrups (try to jump also, trot rising...)
You need to be really straight otherwise your legs will go backwards automatically, think about bending your joints and don't rise too high on the jumps.
Also, don't forget to put weight on your heels.
I hope i could help you :)