I was able to get the solution.
second_bar = bar_index - ta.valuewhen(AB_crossover==true and nz(AB_crossover[1], false)==false, bar_index, 1)
third parameter is key.
0: last condition 1: last second condition