本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © StratifyTrade
//@version=5
indicator(
"Liquidity Trendline With Signals [StratifyTrade]"
, "StratifyTrade - Liquidity Trendline With Signals"
, overlay = true
, max_lines_count = 500
, max_bars_back = 5000
)
len = input.int (5 , "Period " , tooltip = "Lookback period", inline = "a", group = "SETTINGS")
cup = input.color(#0044ff, "" , "" , inline = "a", group = "SETTINGS")
cdn = input.color(#ff2b00, "" , "" , inline = "a", group = "SETTINGS")
space = input.float(2 , "Padding" , tooltip = "Padding distance", inline = "b", group = "SETTINGS", step = 0.1)
shs = input.bool (true , "Show Breakouts", inline = "z", group = "SETTINGS")
ph = ta.pivothigh(high, len, len)
pl = ta.pivotlow (low , len, len)
type store
float src
int n
type bar
float o = open
float h = high
float l = low
float c = close
int n = bar_index
float v = volume
type draw
line[] upln
line[] dnln
var store[] upbin = array.new<store>()
var store[] dnbin = array.new<store>()
var draw d = draw.new(array.new<line>(), array.new<line>())
bar b = bar.new()
atr = ta.atr(200)
method slope(line ln) =>
x = ln.get_x2() - ln.get_x1()
y = ln.get_y2() - ln.get_y1()
y / x
vol() =>
math.min(atr * 0.1, close * (0.1/100))
var bool broken = false
color active = na
bool plup = false
bool pldn = false
if ph
bool remove = false
var bool valid = false
upbin.unshift(store.new(b.h[len], b.n[len]))
if upbin.size() > 1
current = upbin.get(0)
before = upbin.get(1)
if current.src < before.src
if broken
valid := true
else
valid := false
if upbin.size() > 3
pastold = upbin.get(3)
pastcur = upbin.get(2)
now = upbin.get(1)
late = upbin.get(0)
if now.src < pastcur.src and now.src < pastold.src and late.src < pastcur.src and late.src < pastold.src
valid := true
else
valid := false
else
valid := false
if valid
d.upln.unshift(line.new(x1 = before.n, x2 = current.n, y1 = before.src , y2 = current.src , color = cdn))
d.upln.unshift(line.new(x1 = before.n, x2 = current.n, y1 = before.src - vol() * space, y2 = current.src - vol() * space, color = cdn))
ln = d.upln.get(1)
for i = 0 to (b.n - before.n)
slope = ln.slope()
ln.set_x2(b.n[i])
ln.set_y2(ln.get_y2() - slope)
if low[i] > ln.get_y2()
remove := true
break
if remove
d.upln.get(0).delete()
d.upln.get(1).delete()
d.upln .clear()
upbin .clear()
broken := true
else
d.upln.get(0).delete()
d.upln.get(1).delete()
d.upln .clear ()
d.upln.unshift(line.new(x1 = before.n, x2 = current.n, y1 = before.src , y2 = current.src , color = cdn))
d.upln.unshift(line.new(x1 = before.n, x2 = current.n, y1 = before.src - vol() * space, y2 = current.src - vol() * space, color = cdn))
linefill.new(d.upln.get(0), d.upln.get(1), color = color.new(cdn, 75))
upbin.clear()
broken := false
if d.upln.size() > 1
btm = d.upln.get(0)
top = d.upln.get(1)
if b.l > top.get_y2()
d.upln.clear()
broken := true
upbin.clear()
plup := true
if d.upln.size() > 1
slup = top.slope()
sldn = btm.slope()
top.set_x2(b.n)
top.set_y2(top.get_y2() + slup)
btm.set_x2(b.n)
btm.set_y2(btm.get_y2() + sldn)
if pl
bool remove = false
var bool valid = false
dnbin.unshift(store.new(b.l[len], b.n[len]))
if dnbin.size() > 1
current = dnbin.get(0)
before = dnbin.get(1)
if current.src > before.src
if broken
valid := true
else
valid := false
if dnbin.size() > 3
pastold = dnbin.get(3)
pastcur = dnbin.get(2)
now = dnbin.get(1)
late = dnbin.get(0)
if now.src > pastcur.src and now.src > pastold.src and late.src > pastcur.src and late.src > pastold.src
valid := true
else
valid := false
else
valid := false
if valid
d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 = before.src , y2 = current.src , color = cup))
d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 = before.src + vol() * space, y2 = current.src + vol() * space, color = cup))
ln = d.dnln.get(1)
for i = 0 to (b.n - before.n)
slope = ln.slope()
ln.set_x2(b.n[i])
ln.set_y2(ln.get_y2() - slope)
if high[i] < ln.get_y2()
remove := true
break
if remove
d.dnln.get(0).delete()
d.dnln.get(1).delete()
d.dnln .clear ()
dnbin .clear ()
broken := true
else
d.dnln.get(0).delete()
d.dnln.get(1).delete()
d.dnln .clear ()
d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 = before.src, y2 = current.src, color = cup))
d.dnln.unshift(line.new(x1 = before.n, x2 = current.n, y1 = before.src + vol() * space, y2 = current.src + vol() * space, color = cup))
linefill.new(d.dnln.get(0), d.dnln.get(1), color = color.new(cup, 75))
dnbin.clear()
broken := false
if d.dnln.size() > 1
btm = d.dnln.get(0)
top = d.dnln.get(1)
if b.h < btm.get_y2()
d.dnln.clear()
broken := true
dnbin.clear()
pldn := true
if d.dnln.size() > 1
slup = top.slope()
sldn = btm.slope()
top.set_x2(b.n)
top.set_y2(top.get_y2() + slup)
btm.set_x2(b.n)
btm.set_y2(btm.get_y2() + sldn)
plotshape(pldn and shs ? b.h[1] : na, "Breaking Down", shape.triangledown, location = location.abovebar, color = cdn , offset = -1, size = size.tiny)
plotshape(plup and shs ? b.l[1] : na, "Breaking Up" , shape.triangleup , location = location.belowbar, color = cup, offset = -1, size = size.tiny)