Is there a way to find a pivot between two signals?  I have tried to use the fold function and can't seem to get it to work.  The image below was taken from the SPY today (11/16/2022).  Below is the code I wrote to generate the signals.
		
		
	
	
		
	
	
	
	
	
	
		
	
		
			
		
		
	
				
			
		Code:
	
	# Trend Pivot using EMA
# Created by Mark Beach - 11/2022
input ShortEmaLength = 10;
input LongEmaLength = 50;
def price_h = high;
plot ema_long = ExpAverage(price_h, ShortEmaLength);
ema_long.setDefaultColor(Color.Cyan);
plot ema_short = ExpAverage(price_h, LongEmaLength);
ema_short.setDefaultColor(Color.Yellow);
def above_trend_start = if ema_short[1] > ema_long[1] and ema_short[0] < ema_long[0] then 1 else Double.NaN;
def above_trend_end = if ema_short[1] < ema_long[1] and ema_short[0] > ema_long[0] then 1 else Double.NaN;
def above_trend;
if above_trend_start {
    above_trend = 1;
} else if above_trend_end {
    above_trend = Double.NaN;
} else {
    above_trend = above_trend[1];
}
AddChartBubble(yes, price_h,
   "AT: " + above_trend +
   "\nATS: " + above_trend_start +
   "\nATE: " + above_trend_end +
   "\nH: " + price_h
, Color.WHITE, yes);