May be, there is a syntax error in your G-Code. If you post it here, we can have a look.
You mentioned, that you can move the spindle in MPG mode, so I assume, the end switches are configured correct and do not stop the movement. But you should double check this also!