Trader1194
New member
Hello all, I am new to trying to mess with ThinkScript but I found a study that I am trying to make some small changes to. I figured out how to get the correct time to show on the chart bubbles, but I cannot get by this error when trying to add a "0" placeholder prior to any number that comes back from the minutes that is less than 10. Otherwise times like 15:02 just show up as 15:2. Any idea how to get passed this?
The error is as follows: Wrong type cast: different types after then and else: double vs class java.lang.String
Any help is really appreciated, thank you
The error is as follows: Wrong type cast: different types after then and else: double vs class java.lang.String
Any help is really appreciated, thank you
Code:
# Identify pre-market and after-hours trading periods
input pre_market_start = 0359;
input pre_market_end = 0929;
input after_hours_start = 1559;
input after_hours_end = 2100;
def pre_market = SecondsFromTime(pre_market_start) > 0 and SecondsFromTime(pre_market_end) < 0;
def after_hours = SecondsFromTime(after_hours_start) > 0 and SecondsFromTime(after_hours_end) < 0;
# Find pre-market and after-hours highs and lows
def pre_market_low = if pre_market then low else Double.NaN;
def pre_market_high = if pre_market then high else Double.NaN;
def after_hours_low = if after_hours then low else Double.NaN;
def after_hours_high = if after_hours then high else Double.NaN;
def pm_low = LowestAll(pre_market_low);
def pm_high = HighestAll(pre_market_high);
def ah_low = LowestAll(after_hours_low);
def ah_high = HighestAll(after_hours_high);
#Example Time_Gettime
#Sleepz 20210315
#Usethinkscript request
#Time Stamp based upon Gettime and RegularTradingStart. Choose timezone
input timezone = {default "ET", "CT", "MT", "PT"};
def starthour = (if timezone == timezone."ET"
then 9
else if timezone == timezone."CT"
then 8
else if timezone == timezone."MT"
then 7
else 6) ;
def hour = Floor(((starthour * 60 + 30) + (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000) / 60);
def minutes = Max(00.00, (GetTime() - RegularTradingStart(GetYYYYMMDD())) / 60000 - ((hour - starthour) * 60 + 30) + 60);
def MinutePlaceholder;
def LowMinute = minutes < 10;
# Add leading zero if minutes is less than 10
if LowMinute then {
MinutePlaceholder = 1; } else {MinutePlaceholder = 0; } ;
# Format minutes with leading zero if necessary
def formatted_minutes = if MinutePlaceholder then Concat("0", minutes) else minutes;
AddChartBubble(pre_market and low == pm_low, pm_low, "Pre-Market Low\n" + (hour) + ":" + formatted_minutes + "\n$" + AsPrice(pm_low), Color.RED, no);
AddChartBubble(pre_market and high == pm_high, pm_high, "Pre-Market High\n" + (hour) + ":" + formatted_minutes + "\n$" + AsPrice(pm_high), Color.GREEN, yes);
AddChartBubble(after_hours and low == ah_low, ah_low, "After-Hours Low\n" + (hour) + ":" + formatted_minutes + "\n$" + AsPrice(ah_low), Color.RED, no);
AddChartBubble(after_hours and high == ah_high, ah_high, "After-Hours High\n" + (hour) + ":" + formatted_minutes + "\n$" + AsPrice(ah_high), Color.GREEN, yes);