Hi all, I am getting error when running this code on thinkorswim with the message as “expected double when decleraing time variable;
declare lower;
# User inputs
input fastLength = 12;
input slowLength = 50;
input endHour = 9;
input endMinute = 30;
# Variables for current time
def currentHour = GetHour(); # Retrieves the current hour of the bar
def currentMinute = GetMinute(); # Retrieves the current minute of the bar
# Determine premarket status
def isPremarket = if currentHour < endHour or (currentHour == endHour and currentMinute <= endMinute) then 1 else 0;
# Variables for premarket high and low
rec premarketHigh = if isPremarket then Max(high, premarketHigh[1]) else premarketHigh[1];
rec premarketLow = if isPremarket then Min(low, premarketLow[1]) else premarketLow[1];
# Trend functions
def fastEMA = ExpAverage(close, fastLength);
def slowEMA = ExpAverage(close, slowLength);
def fastEMA_Short = ExpAverage(close, 5);
def slowEMA_Short = ExpAverage(close, 12);
def trend1250 = if fastEMA > slowEMA then 1 else -1; # 1 for Bullish, -1 for Bearish
def trend512 = if fastEMA_Short > slowEMA_Short then 1 else -1; # 1 for Bullish, -1 for Bearish
# Chop or Trend determination
def chopOrTrend = if close > premarketHigh or close < premarketLow then 1 else 0;
# 1 for Trending, 0 for Chop Range
# Price Action Trend
def priceActionTrend =
if chopOrTrend and close > premarketHigh then 1
else if chopOrTrend and close < premarketLow then -1
else 0;
# 1 for Bullish, -1 for Bearish, 0 for Chop Range
# Convert numerical conditions to strings for AddLabel
AddLabel(yes,
“Price Action: ” +
(if priceActionTrend == 1 then “Bullish” else if priceActionTrend == -1 then “Bearish” else “Chop Range”),
if priceActionTrend == 1 then Color.GREEN else if priceActionTrend == -1 then Color.RED else Color.ORANGE);
AddLabel(yes,
“Ripster Clouds 12/50: ” + (if trend1250 == 1 then “Bullish” else “Bearish”),
if trend1250 == 1 then Color.GREEN else Color.RED);
AddLabel(yes,
“Ripster Clouds 5/12: ” + (if trend512 == 1 then “Bullish” else “Bearish”),
if trend512 == 1 then Color.GREEN else Color.RED);
# Highlighting premarket levels
plot premarketHighPlot = premarketHigh;
premarketHighPlot.SetDefaultColor(Color.LIGHT_GREEN);
premarketHighPlot.SetStyle(Curve.SHORT_DASH);
plot premarketLowPlot = premarketLow;
premarketLowPlot.SetDefaultColor(Color.LIGHT_RED);
premarketLowPlot.SetStyle(Curve.SHORT_DASH);