我从tradingview文档中找到了一个枢轴点高低的例子,但是由于我的其他代码是在版本3或2中编写的,所以它没有与其他代码一起运行。更改我的其他代码很麻烦,因为它很长。
所以我的选择是弄清楚如何在版本4(而非4)中执行版本4中的枢轴点。
//@version=4
study("Pivot Points High Low", shorttitle="Pivots HL", overlay=true)
lenH = input(title="Length High", type=input.integer, defval=10, minval=1)
lenL = input(title="Length Low", type=input.integer, defval=10, minval=1)
//if i run the code in version 3, this len below causes problems
fun(src, len, isHigh, _style, _yloc, _color) =>
p = nz(src[len])
isFound = true
for i = 0 to len - 1
if isHigh and src[i] > p
isFound := false
if not isHigh and src[i] < p
isFound := false
for i = len + 1 to 2 * len
if isHigh and src[i] >= p
isFound := false
if not isHigh and src[i] <= p
isFound := false
if isFound
label.new(bar_index[len], p, tostring(p), style=_style, yloc=_yloc, color=_color)
// good news. i can change the color to white and it will at least look decent even though it loses the arrow point
fun(high, lenH, true, label.style_labeldown, yloc.abovebar, color.lime)
fun(low, lenL, false, label.style_labelup, yloc.belowbar, color.red)
任何提示都值得赞赏
答案 0 :(得分:0)
//@version=3
study("Pivot Points High Low", shorttitle="Pivots HL v3", overlay=true)
lenH = input(title="Length High", defval=10, minval=1)
lenL = input(title="Length Low", defval=10, minval=1)
fun(src, len, isHigh) =>
p = nz(src[len])
isFound = true
for i = 0 to len - 1
if isHigh and src[i] > p
isFound := false
if not isHigh and src[i] < p
isFound := false
for i = len + 1 to 2 * len
if isHigh and src[i] >= p
isFound := false
if not isHigh and src[i] <= p
isFound := false
return = isFound ? p : na
pivotHi = fun(high, lenH, true)
pivotLo = fun(low, lenL, false)
plotchar(pivotHi, "PivotHi", "—", location.absolute, lime, 0, offset = -lenH, size = size.large)
plotchar(pivotLo, "PivotLo", "—", location.absolute, red, 0, offset = -lenL, size = size.large)