Untitled

 avatar
unknown
plain_text
21 days ago
1.2 kB
22
Indexable
//@version=5
indicator("Candle High/Low Digital Root", overlay=false)

// Function to calculate digital root
f_digitalRoot(_num) =>
    // Convert number to string and remove decimal point
    _str = str.tostring(_num, "#.##########")
    _str := str.replace_all(_str, ".", "")
    // Sum digits
    _sum = 0
    for i = 0 to str.length(_str) - 1
        _sum := _sum + str.tonumber(str.substr(_str, i, 1))
    // Reduce to single digit
    while _sum > 9
        _temp = _sum
        _sum := 0
        _temp_str = str.tostring(_temp)
        for j = 0 to str.length(_temp_str) - 1
            _sum := _sum + str.tonumber(str.substr(_temp_str, j, 1))
    _sum

// Calculate digital roots for high and low
highRoot = f_digitalRoot(high)
lowRoot = f_digitalRoot(low)

// Plot results
plot(highRoot, "High Digital Root", color.blue, 2)
plot(lowRoot, "Low Digital Root", color.red, 2)

// Add labels for the last bar
if barstate.islast
    label.new(bar_index, highRoot, "High: " + str.tostring(highRoot), color=color.blue, style=label.style_label_down)
    label.new(bar_index, lowRoot, "Low: " + str.tostring(lowRoot), color=color.red, style=label.style_label_up)
Editor is loading...
Leave a Comment