Did you put a ( rebuilt engine ) in the truck or is your idea of new really a used engine ?
Here is a link to another Forum where a similar problem and code devolved after a engine swap was done where a used engine was installed.
His problem turned out to be a Harness that was used from the used engine he installed, installing the original harness cured the problem.
https://www.ranger forums .com/4-0l-...-input-151804/
If this does not help and you really installed a rebuilt or somehow a new engine in the truck using the original harness and accessories let us know and we can help try and pin point the problem.
But my first recommendation would be is to double check your work, Look for disconnected, dry rotted, cracked or leaking vacuum lines, loose electrical connections pinched wires, wiring harnesses or vacuum lines not installed routed correctly.
Even check for ground wires left disconnected or poorly grounded.