irontrades
New member
I created a strategy that had been working fine all last year. This year, it suddenly stopped working. I noticed that on 1/10/25, the VVIX SMA calculation begins to return "NaN". I believe this is the root of my problem. I've done alot of digging on this and have not found a solution yet.
	
	
	
	
	
		
	
		
			
		
		
	
				
			
		Code:
	
	# IVTS and VVIX Strategy for VIX Options (Enter/Exit on Open)
input ivtsSymbol1 = "VIX";
input ivtsSymbol2 = "VIX3M";
input ivtsLength = 5;
input vvixSMALength = 200;
def ivtsRatio = close(ivtsSymbol1) / close(ivtsSymbol2);
def ivtsMedian = Median(ivtsRatio, ivtsLength);
# Request daily aggregation for VVIX so it updates as expected
def vvix = close("VVIX", period = AggregationPeriod.DAY);
def vvixSMA = SimpleMovingAvg(vvix, vvixSMALength);
# Entry and exit conditions based on previous day's data
def entryCondition = ivtsMedian[1] < 1 and vvix[1] < vvixSMA[1];
def exitCondition = ivtsMedian[1] > 1 or vvix[1] > vvixSMA[1];
# Trading logic
rec inTrade = CompoundValue(1, if entryCondition and !inTrade[1] then 1 else if exitCondition and inTrade[1] then 0 else inTrade[1], 0);
# Generate signals for next open
def enterSignal = entryCondition and !inTrade[1];
def exitSignal = inTrade[1] and exitCondition;
# Plot signals
plot EnterPlot = enterSignal;
plot ExitPlot = exitSignal;
plot InTradePlot = inTrade;
EnterPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
EnterPlot.SetLineWeight(3);
EnterPlot.SetDefaultColor(Color.GREEN);
ExitPlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
ExitPlot.SetLineWeight(3);
ExitPlot.SetDefaultColor(Color.RED);
InTradePlot.SetPaintingStrategy(PaintingStrategy.BOOLEAN_POINTS);
InTradePlot.SetLineWeight(3);
InTradePlot.SetDefaultColor(Color.CYAN);
# Labels
AddLabel(yes, "IVTS Median: " + AsText(ivtsMedian[1], NumberFormat.TWO_DECIMAL_PLACES), Color.WHITE);
AddLabel(yes, "VVIX: " + AsText(vvix[1], NumberFormat.TWO_DECIMAL_PLACES), Color.WHITE);
AddLabel(yes, "VVIX SMA: " + AsText(vvixSMA[1], NumberFormat.TWO_DECIMAL_PLACES), Color.WHITE);
AddLabel(yes, "Enter Next Open: " + if enterSignal then "Yes" else "No", Color.GREEN);
AddLabel(yes, "Exit Next Open: " + if exitSignal then "Yes" else "No", Color.RED);
AddLabel(yes, "In Trade: " + (if inTrade then "Yes" else "No"), Color.YELLOW);
# Alerts for entry and exit signals
Alert(enterSignal, "IVTS-VVIX Entry Signal for Next Open", Alert.BAR, Sound.Ding);
Alert(exitSignal, "IVTS-VVIX Exit Signal for Next Open", Alert.BAR, Sound.Chimes);