As far as I am aware you can’t set the distance because the axis needs to move off the switch only as much as it takes for the switch to be reset.
If you have ‘switch bounce’ then a false signal will be sent and this may be the cause of your problem.
Try increasing the de-bounce interval (Config / General Config) and see if this helps. (Ideally this needs to be set to the lowest, reliable, value which cures the problem).
Tweakie.