This script is a conversion from the metatrader perfect trend line indicator. The multi-timeframe setup shows smooth trends.
Alerts on cross of the fast and slow trendline can be setup in alerts section.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © QuantG
//@version=5
indicator(title="QG_PerfectTrendLine",overlay=true, timeframe="")
//PERFECT TRENDLINE
// --- settings
SlowLength = input(9, "TrendLine Slow Length") // Slow length
FastLength = input(5, "TrendLine Fast Length") // Fast length
// --- end of settings
fasthigh = ta.highest(high, SlowLength)
fastlow = ta.lowest(low, SlowLength)
slowhigh = ta.highest(high, FastLength)
slowlow = ta.lowest(low, FastLength)
thighs = 0.0
tlows = 0.0
if high<slowhigh
thighs:=slowhigh
else
thighs:=high
if low>slowlow
tlows:=slowlow
else
tlows:=low
thighf=0.0
tlowf=0.0
if high<fasthigh
thighf:=fasthigh
else
thighf:=high
if low>fastlow
tlowf:=fastlow
else
tlowf:=low
slowln=0.0
fastln=0.0
if close>slowln[1]
slowln:=tlows
else
slowln:=thighs
if close>fastln[1]
fastln:=tlowf
else
fastln:=thighf
trend=-1
if close<slowln and close<fastln
trend:=1
if close>slowln and close>fastln
trend:=0
pf = plot(fastln, color=color.new(color.red,10))
ps = plot(slowln, color=color.new(color.green,10))
_color = color.white
_color := fastln>slowln ?color.new(color.red,70) : fastln<slowln ? color.new(color.green,70) : _color[1]
fill(pf,ps, color = _color)
Long=fastln[1]<slowln[1] and fastln[0]>slowln[0]
Short=fastln[1]>slowln[1] and fastln[0]<slowln[0]
alertcondition(Long,title="Long Signal",message="Enter Long")
alertcondition(Short,title="Short Signal",message="Enter Short")
Comments