Angle Baby from Juiida
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © juiida

//@version=5
indicator('Angle Baby', overlay=true, max_bars_back=5000)

calcDegree(src, period) =>
    rad2degree = 180 / 3.14159265359
    ang = rad2degree * math.atan((src[0] - src[period]) / period)

src = input(hlc3, title='Source')
enable_kalman_filter = input.string('ON', title='Filter', options=['ON', 'OFF'])
period1 = input.int(30, 'Slow EMA Period ', minval=1)
period2 = input.int(9, 'Fast EMA Period ', minval=1)
ma1 = ta.ema(src, period1)
ma2 = ta.ema(src, period2)


plot(ma1, 'SLOW EMA', color=color.new(color.orange, 0), linewidth=2)
plot(ma2, 'FAST EMA', color=color.new(color.aqua, 0), linewidth=2)

count = ta.barssince(ta.crossunder(ma1, ma2))
count1 = ta.barssince(ta.crossover(ma1, ma2))

i_anglePriceSrc = input.source(high, title='Bull Angle Source', group='angles setting')
i_anglePriceSrc1 = input.source(low, title='Bear Angle Source', group='angles setting')
i_anglePeriod = count
i_anglePeriod1 = count1

angle = calcDegree(i_anglePriceSrc, i_anglePeriod)
angle1 = calcDegree(i_anglePriceSrc1, i_anglePeriod1)

label juiida1 = label.new(time, close, text='             ✍️ Angle Dashboard ✍️' + '\n━━━━━━━━━━━━━━━' + '\n           🟢 Bullish Angle 🟢' + '\n━━━━━━━━━━━━━━━' + '\n      From Crossunder          | ' + str.tostring(angle, '##.##') +'\n━━━━━━━━━━━━━━━' + '\n             🔴 Bear Angle   🔴' +'\n━━━━━━━━━━━━━━━' +'\n      From Crossover            | '+ str.tostring(angle1, '##.##') +'\n━━━━━━━━━━━━━━━' +'\n              From, -JuiiDa 🔥', color=color.black, xloc=xloc.bar_time, style=label.style_label_left, textcolor=color.white, textalign=text.align_left) 
label.set_x(juiida1, label.get_x(juiida1) + math.round(ta.change(time) * 14))
label.delete(juiida1[1])

line l = na
line.delete(l[1])
l := line.new(bar_index[i_anglePeriod], i_anglePriceSrc[i_anglePeriod], bar_index, i_anglePriceSrc, color=color.lime)

line l1 = na
line.delete(l1[1])
l1 := line.new(bar_index[i_anglePeriod1], i_anglePriceSrc1[i_anglePeriod1], bar_index, i_anglePriceSrc1, color=color.red)




