'Alert after price crosses MA, BUT wait for x amount $ to drop or rise

I'm new to coding and I'm trying to code an alert that triggers when the price moves a specific amount of $ above or below after an MA cross.

I've tried different things, and now it's gotten so convoluted I'm lost. This is what works best so far but not really because the alert triggers after two consecutive Renko box closes, so doesn't work when not consecutive...any ideas?? Thanks. I'm currently using a combination of crossover and rising and barssince but it doesn't work.

    //@version=5  
    indicator('SMA21', overlay=true)  
    ma = ta.sma(close, 21)  
    maCrossUp = ta.crossover(close, ma)  
    maCrossDn = ta.crossunder(close, ma)  
   
    cond1= ta.rising(close,2)  
    cond2= ta.falling(close,2)  


    xUp = (ta.barssince(maCrossUp) == 1)  
    xDn = (ta.barssince(maCrossDn) == 1)  

    if xUp and cond1  
    // Trigger the alert the first time a cross occurs during the closed bar.  
    alert('Price (' + str.tostring(close) + ') crossed over MA ('  + str.tostring(ma) +').', alert.freq_once_per_bar_close)  
    
   
  

    if xDn and cond2  
    // Trigger the alert the first time a cross occurs during the closed bar.  
    alert('Price (' + str.tostring(close) + ') crossed under MA (' + str.tostring(ma) + ').', alert.freq_once_per_bar_close)  

    plot(ma)  
    plotshape(xUp and cond1, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), title='xUp')  
    plotshape(xDn and cond2, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), title='xDn')  

    //Trigger alert condition
    alertcondition(xUp and cond1 or xDn cond2, title='Alert Condition', message='Price crossed over MA')


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source