If you have a closed system you need an expansion tank but I don't think that's what is causing the hammer effect. Just because your toilet is close doesn't necessarily mean the piping is close and without bends. Can you get to the drop to the toilet? I would as an experiment put a hammer arrestor at the top of the drop.
Are your pipes secured to structure, almost sounds like besides the hammer you might have some loose pipes.