To me (and I'm not a model rail guy, but I believe a number of members are so you will surely get specific help) that the key here is so-called state change detection. That means you don't simply sense the presence or absence of the train, but rather the arrival of it at (say) the left sensor (if train is going left to right) and its departure from the right hand one.
Arrival means the sensor reading went from no detection to detection; departure is the change from detection to no detection.
Arrival at the left would close the gates to cars, and prime the right-hand sensor so that if the gates are closed and the right hand sensor goes from train to not a train, the gates open.
But first, before getting to the details, I suggest looking at the state change detection example here, or a different (active low) version here.