One thing that helps is spending it immediately on a hero upgrade. Those high amounts i got nailed with were usually when my storage was full and i had no free builders. Also helps to empty to collectors as much as possible. I also watch the attacks on replay and tinker with moving bombs, defenses , etc. based on where and what people attack with.
Can't seem to protect my TH very well, though. Last raid did 31% and got shit for loot but killed my TH.
I've been throwing ALL my extra loot into walls immediately which keeps my loot totals down. (You can see in my screenie i had almost no elixir) That helps minimize the # of times i get raided and the loot people get. I think only one screen shows a loss over 250k (500 total) I can have 5 mill gold/elixer and dissapear that with four walls. Lately, i've been keeping one builder free at all times just for walls.