this should work if the order placed in the last 20 candles is still open. if it was opened 18 candles ago and closed 10 candles ago this will not detect the order. If it's important to know if there was ANY order, tell me and I try to help.
barsSinceLastEntry()=>
strategy.opentrades > 0 ? (bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades-1)) : na