Electronic board sold by several companies. The Lionel and other units use an infra-red detector to sense the trolley and cut power for a time you can set. For the end (such as stopping at a terminal with a bumper that would normally reverse the trolley) install the sensor unit ahead of the bumper. BUT it has to be able to gain enough speed so it trips when it hits- a few inches would normally be enough.
A Lionel 153IR can be used for this. Z Stuff for Trains also make a unit (DZ-1220) for about $120 that has a stop feature, plus sound generator through a supplied speaker. Might be best to buy the Z Stuff products through Ross Custom Switches.