本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LonesomeTheBlue
//@version=4
study("Price Change Rate by Pivot Points - Dynamic", overlay=true, max_bars_back = 2000)
prd = input(defval = 30, title="Pivot Point Period", minval = 20, maxval = 100)
showpivot = input(defval = true, title="Show Pivot Points")
float ph = na, float pl = na
ph := pivothigh(prd, prd)
pl := pivotlow(prd, prd)
plotshape(ph and showpivot, text="H", style=shape.labeldown, color=na, textcolor=color.blue, location=location.abovebar, transp=0, offset = -prd)
plotshape(pl and showpivot, text="L", style=shape.labeldown, color=na, textcolor=color.blue, location=location.belowbar, transp=0, offset = -prd)
_highest(len) =>
_hi = high
for i = 1 to len -1
if na(high[i])
break
_hi := max(_hi, nz(high[i]))
_hi
_lowest(len) =>
_lo = low
for i = 1 to len -1
if na(low[i])
break
_lo := min(_lo, low[i])
_lo
hcont = true
hcont := pl ? false : nz(hcont[1], true)
lcont = true
lcont := ph ? false : nz(lcont[1], true)
float lastphi = na, float lastplo = na
hiloc = 0, loloc = 0
lastphi := nz(lastphi[1])
lastplo := nz(lastplo[1])
hiloc := nz(hiloc[1]) + 1
loloc := nz(loloc[1]) + 1
hchg = false
if ph
if (hcont and lastphi != 0 and ph > lastphi) or not hcont
hchg := (hcont and lastphi != 0 and ph > lastphi)
lastphi := ph
hiloc := prd
hcont := true
lchg = false
if pl
if (lcont and lastplo != 0 and pl < lastplo) or not lcont
lchg := (lcont and lastplo != 0 and pl < lastplo)
lastplo := pl
loloc := prd
lcont := true
lw = _lowest(hiloc)
var line lnd = na
var label lbd = na
if hiloc != 0 and lastphi != 0
if change(lastphi) == 0 or hchg
line.delete(lnd)
label.delete(lbd)
lnd := line.new(bar_index - hiloc, lastphi, bar_index - hiloc, lw, color = color.red, style = line.style_arrow_right)
txt = tostring(lastphi) + "\n" + tostring(lw) + "\n -% " + tostring(((lastphi - lw) / lastphi) * 100, '#.#')
lbd := label.new(bar_index - hiloc, lw, text = txt, color = color.red, textcolor = color.white, style = label.style_label_up)
lw := _highest(loloc)
var line lnu = na
var label lbu = na
if loloc != 0 and lastplo != 0
if change(lastplo) == 0 or lchg
line.delete(lnu)
label.delete(lbu)
lnu := line.new(bar_index - loloc, lastplo, bar_index - loloc, lw, color = color.lime, style = line.style_arrow_right)
txt = tostring(lastplo) + "\n" + tostring(lw) + "\n +% " + tostring(((lw - lastplo) / lastplo) * 100, '#.#')
lbu := label.new(bar_index - loloc, lw, text = txt, color = color.lime, textcolor = color.black, style = label.style_label_down)