// Function to get timestamp for 9:05 AM in UTC+5:30 getNineFiveTime(year, month, day) => timestamp("UTC+5:30", year, month, day, 9, 5)
// Initialize variables var float nineFivePrice = na var int totalDigitSum = 0 var int partialDigitSum = 0 var label nineFiveLabel = na // Initialize the label variable
// Capture the 9:05 AM candle close price only once if (time == getNineFiveTime(year(timenow), month(timenow), dayofmonth(timenow)) and na(nineFivePrice)) nineFivePrice := close
// Calculate the sum of all digits if (not na(nineFivePrice)) priceStr = str.replace(str.tostring(math.abs(nineFivePrice)), ".", "") totalDigitSum := 0 for i = 0 to str.length(priceStr) - 1 digitStr = str.substring(priceStr, i, i + 1) if str.length(digitStr) > 0 digit = str.tonumber(digitStr) if not na(digit) totalDigitSum += int(digit)
// Calculate the sum of digits (integer part only) if (not na(nineFivePrice)) intPrice = int(math.abs(nineFivePrice)) priceStrInt = str.tostring(intPrice) partialDigitSum := 0 for i = 0 to str.length(priceStrInt) - 1 digitStrInt = str.substring(priceStrInt, i, i + 1) if str.length(digitStrInt) > 0 digit = str.tonumber(digitStrInt) if not na(digit) partialDigitSum += int(digit)
// Display the 9:05 AM price and sums in a label (above candles) if (not na(nineFivePrice)) if na(nineFiveLabel) // Create the label only once nineFiveLabel := label.new(bar_index, high, "9:05 AM Price: " + str.tostring(nineFivePrice, "#.##") + ", Total Sum: " + str.tostring(totalDigitSum) + ", Partial Sum (Int): " + str.tostring(partialDigitSum), style=label.style_label_left, size=size.normal, color=color.blue, textcolor=color.white) else label.set_text(nineFiveLabel, "9:05 AM Price: " + str.tostring(nineFivePrice, "#.##") + ", Total Sum: " + str.tostring(totalDigitSum) + ", Partial Sum (Int): " + str.tostring(partialDigitSum)) label.set_y(nineFiveLabel, high + (high * 0.001)) // Position slightly above high label.set_x(nineFiveLabel, bar_index)