My trick may sound stupid, but it does work and is beneficial in two senses. What I do is to drink quite a lot of water while coding.
I have a 1 litre bottle that I must empty and refill at least twice a day. Every time I need to refill the bottle or... empty myself, I seize the opportunity to rest for 5 minutes. That's all.
I guarantee you will get up from your chair and leave everything you're doing.