I couldn't replicate the problem you describe, but if you add /targetenemy to the beginning, if you have no target it will target the nearest enemy before locking on. I would also recommend a macro lock at the beginning so that all the lines execute even if another macro tries to interrupt it.
Give that a shot and see if it works better for you.Code:/mlock /targetenemy /lockon /automove /ac Auto-attack