← All Scripts

Trend follower v2

Pranay Sutradhar
Pranay Sutradhar
2d ago
Trend follower v2

// Smooth Call Put Trend Indicator

indicator("Smooth Call Put Trend", overlay=true)

src = input.source(close, title="Source")
fastLen = input.int(9, title="Fast EMA Length")
slowLen = input.int(21, title="Slow EMA Length")
trendLen = input.int(50, title="Trend EMA Length")
confirmBars = input.int(2, title="Trend Confirmation Bars", minval=1)
atrLen = input.int(14, title="ATR Length")
minGapAtr = input.float(0.10, title="Minimum EMA Gap (ATR)", minval=0.0)
showEma = input.bool(true, title="Show EMAs")
showBars = input.bool(true, title="Color Trend Bars")

fastEma = talib.ema(src, fastLen)
slowEma = talib.ema(src, slowLen)
trendEma = talib.ema(src, trendLen)
atrValue = talib.atr(atrLen)

emaGap = math.abs(fastEma - slowEma)

bullBase = fastEma > slowEma and close > trendEma and emaGap >= atrValue * minGapAtr
bearBase = fastEma < slowEma and close < trendEma and emaGap >= atrValue * minGapAtr

bullConfirmed = bullBase and bullBase[1]
bearConfirmed = bearBase and bearBase[1]

bullSignal = bullConfirmed and not bullConfirmed[1]
bearSignal = bearConfirmed and not bearConfirmed[1]

plot(showEma ? fastEma : na, title="9 EMA", color=color.lime, linewidth=2)
plot(showEma ? slowEma : na, title="21 EMA", color=color.orange, linewidth=2)
plot(showEma ? trendEma : na, title="Trend EMA", color=color.blue, linewidth=2)

plotshape(bullSignal, title="CALL BUY", shape=shape.labelup, location=location.belowbar, color=color.green, text="CALL BUY", textcolor=color.white, size=size.small)

plotshape(bearSignal, title="PUT BUY", shape=shape.labeldown, location=location.abovebar, color=color.red, text="PUT BUY", textcolor=color.white, size=size.small)

barTrendColor = bullConfirmed ? color.green : bearConfirmed ? color.red : na

barcolor(showBars ? barTrendColor : na)

if bullSignal {
alert("CALL BUY: Smooth bullish trend confirmed")
}

if bearSignal {
alert("PUT BUY: Smooth bearish trend confirmed")
}

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by GoCharting. Read more in the Terms of Use.

Comments (0)

Loading comments…