I suggest adding some debug output to your script. The easiest way is to use mcCntlSetLastError(), which outputs to the status/error line at the bottom of the Mach4 screen (and the "history" button gets you all the messages). In each of your "if" and "elseif" cases where you change one of the solenoid control outputs, log the current encoder position and what you are commanding the solenoids to do.
For example,
if zEncoderVal >= zStrokeUp then
mcCntlSetLastError(inst, string.format( "pos %.4f turn output0 on",zEncoderVal) )
mc.mcSignalSetState(output_0, 1)
elseif zEncoderVal > zStrokeDown and zEncoderVal < zStrokeUp and output_0_state == 1 then
etc...
Not tested and you may need to tweak the string.format() to get it to work. Then see what the encoder values are when you make the decisions to change directions.
Even better would be to save the raw encoder value in a separate variable from the one you use to store the value in inches. The output both values in the mcCntlSetLastError() calls, just on the off chance that there is something happening in the conversion to inches (I don't know WHAT might go wrong there, but I do know that when debugging something, collecting more data is almost always the right thing to do).
Bob