You did not provide the code you are using so my solution is going to be of my own application. You will have to figure out how to apply the technique your own code.
input maLengthOne = 8;
input maTypeOne = AverageType.EXPONENTIAL;
input maPriceOne = close;
input maLengthTwo = 21;
input maTypeTwo = AverageType.EXPONENTIAL;
input maPriceTwo = close;
def maOne = MovingAverage(maTypeOne, maPriceOne, maLengthOne);
def maTwo = MovingAverage(maTypeTwo, maPriceTwo, maLengthTwo);
def signal = maOne[1] < maTwo[1] and maOne > maTwo;
rec barNumberOfSignal = if signal then BarNumber() else barNumberOfSignal[1];
plot data = barNumberOfSignal;
The solution creates two moving averages. The signal is for the slow moving average crossing above the slow moving average. The code captures the bar number of the crossover event and retains it until the next crossover event. The technique required to achieve this is known as recursion. Which is when the current value of a variable is derived from a previous value of the same variable (in part or in whole).
If you need the bar number to reset when the other signal occurs you will need to add new logic to the recursive variable to reset the bar number when the other signal occurs. Depending on the complexity of your signals it might as simple as this:
rec barNumberOfSignal = if signalOne or signalTwo then BarNumber() else barNumberOfSignal[1];