You probably have your directions and endstops all muddled up.
If your endstop is on the left its a min endstop and must be configured that way
If your endstop is on the right it is a max endstop and must be configured that way
Direction of travel, the head moves right for +X moves and the head moves left for -X moves
Now depending on your electronics you may have different plugs for min and max endstops
The firmware also need to match this, eg in marlin
// Sets direction of endstops when homing; 1=MAX, -1=MIN
// :[-1,1]
#define X_HOME_DIR -1
also in regards to direction of movement, fine the line
#define INVERT_X_DIR
If its false make it true or if its true make it false
(Or if the stepper plug allows, you can turn the plug over 180 degrees, NB never unplug steppers while the power is on)
You have to make it match your hardware