I piece together this code here that would show arrows if the VIX and the SPX [or any symbol] reach a swing high or swing low point at the same time. I'm not sure why it isn't working correctly. It may be the bn = bar number part of the code. I would appreciate any help!
#declare lower;
################################################################################
################################################################################
# SWING LOW
# define swing low points
input length = 10;
def bn = BarNumber();
################################################################################
################################################################################
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
# identify the very last swing low point
#def lowPointOneBarNumber_delta = HighestAll(if swingLow_delta then bn else 0);
#def lowPointOneValue_delta = if bn == lowPointOneBarNumber_delta then low_delta else lowPointOneValue_delta[1];
#plot low1_delta = if bn < lowPointOneBarNumber_delta then Double.NaN else lowPointOneValue_delta;
#low1_delta.SetDefaultColor(Color.GREEN);
#low1_delta.Hide();
# SWING HIGH
# define swing high points
def swingHigh = high > Highest(high[1], length - 1) and high == GetValue(Highest(high, length), -offset);
# identify the very last swing high point
#def highPointOneBarNumber_delta = HighestAll(if swingHigh_delta then bn else 0);
#def highPointOneValue_delta = if bn == highPointOneBarNumber_delta then high_delta else highPointOneValue_delta[1];
#plot high1_delta = if bn < highPointOneBarNumber_delta then Double.NaN else highPointOneValue_delta;
#high1_delta.SetDefaultColor(Color.LIGHT_RED);
#high1_delta.Hide();
# identify the 2nd to last swing high point
#plot Up_delta = if swingLow then low else Double.NaN;
#Up_delta.SetDefaultColor(Color.GREEN);
#Up_delta.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#Up_delta.SetLineWeight(1);
#Up_delta.Hide();
#plot Down_delta = if swingHigh then high else Double.NaN;
#Down_delta.SetDefaultColor(Color.GREEN);
#Down_delta.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#Down_delta.SetLineWeight(1);
#Down_delta.Hide();
################################################################################
################################################################################
#VIX SWING
input secondarySecurity = "VIX";
def High_VIX = HIGH(secondarySecurity)
;
def Low_VIX = LOW(secondarySecurity);
def Open_VIX = OPEN(secondarySecurity)
;
def Close_VIX = CLOSE(secondarySecurity);
def bn_Vix = Sqr(Correlation(BarNumber(), close_VIX, length));
def lastBar_VIX = HighestAll(if IsNaN(Close_VIX) then 0 else bn_VIX);
def offset_VIX = Min(length - 1, lastBar - bn_VIX);
def swingLow_VIX = Low_VIX < Lowest(Low_VIX[1], length - 1) and Low_VIX == GetValue(Lowest(Low_VIX, length), -offset);
def swingHigh_VIX = High_VIX > Highest(High_VIX[1], length - 1) and High_VIX == GetValue(Highest(High_VIX, length), -offset);
################################################################################
################################################################################
################################################################################
################################################################################
def Op_Buy = swingLow is true && swingHigh_VIX is true;
def Op_Sell = swingHigh_VIX is true && swingLow_VIX is true;
plot Option_Buy = Op_Buy;
Option_Buy.SetLineWeight(1);
Option_Buy.SetDefaultColor(Color.ORANGE);
#Option_Buy.SetDefaultColor(Color.Uptick);
Option_Buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#Option_Buy.Hide();
plot Option_Sell = Op_Sell;
Option_Sell.SetLineWeight(1);
Option_Sell.SetDefaultColor(Color.ORANGE);
#Option_Sell.SetDefaultColor(Color.Downtick);
Option_Sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#Option_Sell.Hide();
#declare lower;
################################################################################
################################################################################
# SWING LOW
# define swing low points
input length = 10;
def bn = BarNumber();
################################################################################
################################################################################
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
# identify the very last swing low point
#def lowPointOneBarNumber_delta = HighestAll(if swingLow_delta then bn else 0);
#def lowPointOneValue_delta = if bn == lowPointOneBarNumber_delta then low_delta else lowPointOneValue_delta[1];
#plot low1_delta = if bn < lowPointOneBarNumber_delta then Double.NaN else lowPointOneValue_delta;
#low1_delta.SetDefaultColor(Color.GREEN);
#low1_delta.Hide();
# SWING HIGH
# define swing high points
def swingHigh = high > Highest(high[1], length - 1) and high == GetValue(Highest(high, length), -offset);
# identify the very last swing high point
#def highPointOneBarNumber_delta = HighestAll(if swingHigh_delta then bn else 0);
#def highPointOneValue_delta = if bn == highPointOneBarNumber_delta then high_delta else highPointOneValue_delta[1];
#plot high1_delta = if bn < highPointOneBarNumber_delta then Double.NaN else highPointOneValue_delta;
#high1_delta.SetDefaultColor(Color.LIGHT_RED);
#high1_delta.Hide();
# identify the 2nd to last swing high point
#plot Up_delta = if swingLow then low else Double.NaN;
#Up_delta.SetDefaultColor(Color.GREEN);
#Up_delta.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#Up_delta.SetLineWeight(1);
#Up_delta.Hide();
#plot Down_delta = if swingHigh then high else Double.NaN;
#Down_delta.SetDefaultColor(Color.GREEN);
#Down_delta.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#Down_delta.SetLineWeight(1);
#Down_delta.Hide();
################################################################################
################################################################################
#VIX SWING
input secondarySecurity = "VIX";
def High_VIX = HIGH(secondarySecurity)
;
def Low_VIX = LOW(secondarySecurity);
def Open_VIX = OPEN(secondarySecurity)
;
def Close_VIX = CLOSE(secondarySecurity);
def bn_Vix = Sqr(Correlation(BarNumber(), close_VIX, length));
def lastBar_VIX = HighestAll(if IsNaN(Close_VIX) then 0 else bn_VIX);
def offset_VIX = Min(length - 1, lastBar - bn_VIX);
def swingLow_VIX = Low_VIX < Lowest(Low_VIX[1], length - 1) and Low_VIX == GetValue(Lowest(Low_VIX, length), -offset);
def swingHigh_VIX = High_VIX > Highest(High_VIX[1], length - 1) and High_VIX == GetValue(Highest(High_VIX, length), -offset);
################################################################################
################################################################################
################################################################################
################################################################################
def Op_Buy = swingLow is true && swingHigh_VIX is true;
def Op_Sell = swingHigh_VIX is true && swingLow_VIX is true;
plot Option_Buy = Op_Buy;
Option_Buy.SetLineWeight(1);
Option_Buy.SetDefaultColor(Color.ORANGE);
#Option_Buy.SetDefaultColor(Color.Uptick);
Option_Buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#Option_Buy.Hide();
plot Option_Sell = Op_Sell;
Option_Sell.SetLineWeight(1);
Option_Sell.SetDefaultColor(Color.ORANGE);
#Option_Sell.SetDefaultColor(Color.Downtick);
Option_Sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#Option_Sell.Hide();