Coral Trend Indicator [LazyBear]  pine v4 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Unknown_TracerBUNNY

//@version=4
// original code by // @author LazyBear 
// I have converted his code to latest PineScript version 4 | I am not the creator of this indicator!
//  I am not the creator of this indicator!, I have only added few lines form line: 20 to line: 25 
// and updated few syntax to latest pine version (eg:- blue to color.blue and similar things like that)
study(title="Coral Trend Indicator [LazyBear] || v4 pine by Unknown_TracerBunny",shorttitle="CTI", overlay=true)
src = input(title="Source", type=input.source, defval=close,group="CTI")
sm =input(21, title="Smoothing Period",group="CTI")
cd = input(0.4, title="Constant D",group="CTI")

bar_col=input(false, title="Color Bars",inline="br",group="Color mode")
flat = input(title="Line", type=input.color, defval=color.new(color.blue,0),inline="br",group="Color mode")

raise = input(title="Color", type=input.color, defval=color.new(color.green,0),inline="col",group="Style")
fall = input(title="Color", type=input.color, defval=color.new(color.red,0),inline="col",group="Style")
di = (sm - 1.0) / 2.0 + 1.0
c1 = 2 / (di + 1.0)
c2 = 1 - c1
c3 = 3.0 * (cd * cd + cd * cd * cd)
c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
var float i1 = na
var float i2 = na
var float i3 = na
var float i4 = na
var float i5 = na
var float i6 = na
i1 := c1*src + c2*nz(i1[1])
i2 := c1*i1 + c2*nz(i2[1])
i3 := c1*i2 + c2*nz(i3[1])
i4 := c1*i3 + c2*nz(i4[1])
i5 := c1*i4 + c2*nz(i5[1])
i6 := c1*i5 + c2*nz(i6[1])

Cto = -cd*cd*cd*i6 + c3*(i5) + c4*(i4) + c5*(i3)
// --------------------------------------------------------------------------
// For the Pinescript coders: Determining trend based on the mintick step. 
// --------------------------------------------------------------------------
//bfrC = Cto - nz(Cto[1]) > syminfo.mintick ? green : Cto - nz(Cto[1]) < syminfo.mintick ? red : blue
bfrC = Cto > nz(Cto[1]) ? raise : Cto < nz(Cto[1])  ? fall : na
tc=bar_col?flat: bfrC
plot(Cto, title="Trend", linewidth=3, style=plot.style_stepline, color=tc,editable=false)
barcolor(bar_col?bfrC:na,editable=false) 

shift_up = (bfrC[1] == fall and bfrC == raise)
shift_dn = (bfrC[1] == raise and bfrC == fall) 
plotshape( shift_up, title = 'Buy',text="Buy",textcolor=raise, style = shape.triangleup, location = location.belowbar, color = #2dac32)
plotshape(shift_dn, title = 'Sell',text="Sell",textcolor=fall, style = shape.triangledown, location = location.abovebar, color = color.orange)

alertcondition(shift_up, title='Alert for Buy', message="Buy")
alertcondition(shift_dn, title='Alert for Sell', message="Sell")
