That's been a problem since Neverwinter Nights.
To avoid it, I use three different things: Auto pause on combat. This way I can give everybody his orders. Selecting of all characters with ctrl+a or ctrl+click on the character images. That way I can get them out of the way easily. And to avoid them running back to the enemy as soon as they reach that point: Hold. Problem there is, that I had characters standing 3 feet away from the enemy without attacking because I didn't tell them.