Hi Sarah,
In your protocol file, you can run a state machine before your main loop, which waits for a TTL and then exits:
sma = NewStateMachine();
sma = AddState(sma, 'Name', 'WaitForTTL', ...
'Timer', 0,...
'StateChangeConditions', {'BNC1High', '>exit'},...
'OutputActions', {});
SendStateMachine(sma);
RawEvents = RunStateMachine;
for currentTrial = 1:nTrials
%... your code...%
end