//@version=4
study(title="UT Bot with HullMA Color Change", overlay = true)
// UT Bot
src = close
keyvalue = input(3, title = "Key Vaule. 'This changes the sensitivity'",
step = .5)
atrperiod = input(10, title="ATR Period")
xATR = atr(atrperiod)
nLoss = keyvalue * xATR
xATRTrailingStop = 0.0
xATRTrailingStop := iff(src > nz(xATRTrailingStop[1], 0) and src[1] >
nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src - nLoss),
iff(src < nz(xATRTrailingStop[1], 0) and src[1] <
nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss),
iff(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss)))
pos = 0
pos := iff(src[1] < nz(xATRTrailingStop[1], 0) and src >
nz(xATRTrailingStop[1], 0), 1,
iff(src[1] > nz(xATRTrailingStop[1], 0) and src <
nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))
xcolor = pos == -1 ? color.red: pos == 1 ? color.green : color.blue
plot(xATRTrailingStop, color = xcolor, title = "Trailing Stop")
buy = crossover(src,xATRTrailingStop)
sell = crossunder(src,xATRTrailingStop)
barcolor = src > xATRTrailingStop
plotshape(buy, title = "Buy", text = 'Buy', style = shape.labelup, location
= location.belowbar, color= color.green,textcolor = color.white, transp =
0, size = size.tiny)
plotshape(sell, title = "Sell", text = 'Sell', style = shape.labeldown,
color= color.red,textcolor = color.white, transp = 0, size = size.tiny)
barcolor(barcolor? color.green:color.red)
alertcondition(buy, title='UT BOT Buy', message='UT BOT Buy')
alertcondition(sell, title='UT BOT Sell', message='UT BOT Sell')
// HullMA
n = input(title="HullMA Period", type=input.integer, defval=16)
n2ma = 2 * wma(close, round(n / 2))
nma = wma(close, n)
diff = n2ma - nma
sqn = round(sqrt(n))
diff1 = na(diff[1]) ? diff : 2 * wma(close[1], round(n / 2)) -
wma(close[1], n)
sqn1 = round(sqrt(n))
n1 = wma(diff, sqn)
n2 = wma(diff1, sqn1)
color_change_up = crossover(n1, n2) // Detects when n1 crosses above n2
(color changes to green)
color_change_down = crossunder(n1, n2) // Detects when n1 crosses below n2
(color changes to red)
c = n1 > n2 ? color.green : color.red
plot(n1, color=c)
// UT Bot based on HullMA color change
if color_change_up
alert("HullMA color changed to green - UT BOT Buy Signal",
alert.freq_once_per_bar_close)
if color_change_down
alert("HullMA color changed to red - UT BOT Sell Signal",
alert.freq_once_per_bar_close)