【问题标题】:tradingview pinescript 15min data on 1sec chart cannot use mutable variable in security function as an argument1sec 图表上的 tradingview pinescript 15min 数据不能使用安全函数中的可变变量作为参数
【发布时间】:2021-05-09 20:55:48
【问题描述】:

我需要在 1 秒图表上使用这个指标,数据来自 15 分钟图表。 我尝试使用安全函数,但这给了我这个错误:不能使用可变变量作为安全函数的参数”

//@version=4

////////
// Fetch Ingredients 
// [
Depth       = input(7, "Depth", input.integer, minval=1, step=1)
Deviation   = input(5, "Deviation", input.integer, minval=1, step=1)
Backstep    = input(2, "Backstep", input.integer, minval=2, step=1)
line_thick  = input(2, "Line Thickness", input.integer, minval=1, maxval=4)
upcolor     = input(color.lime, "Bull Color")
dncolor     = input(color.red, "Bear Color")
repaint     = input(true, "Repaint Levels")
// ]


//////// 
// Bake
// [
var last_h = 1, last_h := last_h + 1
var last_l = 1, last_l := last_l + 1
var lw = 1, var hg = 1
lw := lw + 1, hg := hg + 1
p_lw = -lowestbars(Depth), p_hg = -highestbars(Depth)
lowing = lw == p_lw or low - low[p_lw] > Deviation*syminfo.mintick
highing = hg == p_hg or high[p_hg] - high > Deviation*syminfo.mintick
lh = barssince(not highing[1]), ll = barssince(not lowing[1])
down = barssince(not (lh > ll)) >= Backstep, lower = low[lw] > low[p_lw], higher = high[hg] < high[p_hg]
if lw != p_lw and (not down[1] or lower)
    lw := p_lw < hg ? p_lw : 0
if hg != p_hg and (down[1] or higher)
    hg := p_hg < lw ? p_hg : 0

line zz = na
label point = na
x1 = down ? lw : hg
y1 = down ? low[lw] : high[hg]

if down == down[1]
    if repaint
        label.delete(point[1])
        line.delete(zz[1])
    down
if down != down[1]
    if down
        last_h := hg
    else
        last_l := lw
    if not repaint
        nx = down?last_h:last_l
        zz := line.new(bar_index-nx, down ? high[nx] : low[nx], bar_index-(down?last_l:last_h), down ? low[last_l] : high[last_h], width=line_thick, color=down?upcolor:dncolor)
        point := label.new(bar_index-nx, down ? high[nx] : low[nx], down ? (high[nx] > high[last_h[1]]?"HH":"LH") : (low[nx] < low[last_l[1]] ? "LL" : "HL"), style=down?label.style_label_down:label.style_label_up, size=size.tiny, color=down?dncolor:upcolor, textcolor=color.black, tooltip = down ? (high[nx] > high[last_h[1]]?"Higher High":"Lower High") : (low[nx] < low[last_l[1]] ? "Lower Low" : "Higher Low"))
    down
if repaint
    zz := line.new(bar_index-(down?last_h:last_l), down ? high[last_h] : low[last_l], bar_index-x1, y1, width=line_thick, color=down?dncolor:upcolor)
    point := label.new(bar_index-x1, y1, down ? (low[x1] < low[last_l] ? "LL" : "HL") : (high[x1] > high[last_h]?"HH":"LH"), style=down?label.style_label_up:label.style_label_down, size=size.tiny, color=down?upcolor:dncolor, textcolor=color.black, tooltip = down ? (low[x1] < low[last_l] ? "Lower Low" : "Higher Low") : (high[x1] > high[last_h]?"Higher High":"Lower High"))
// ]

我真正需要的只是指标中的这个逻辑

low[x1] > low[last_l]

我不能简单地将深度从 7 更改为 6300 以获得我想要的结果,因为要处理的蜡烛太多了。 所以我尝试使用安全功能,但无法让它工作。

非常感谢您的帮助。

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    这里有两个问题:

    1. last_l 变量是一个可变变量(使用 := 重新分配),因此需要将其计算封装在一个函数中,然后可以使用 security() 调用该函数。
    2. 这是最重要的问题。您正在计算柱线偏移量,但 HTF 的柱线偏移量无法在图表的时间范围内转换。在 1S 时,15 分钟时 10 条的偏移量是什么意思?无法判断,因为在图表分辨率下 15 分钟 TF 的 1S 膨胀中会有不同数量的柱。

    像 MTF Ichimokus 或 pivot 脚本这样的脚本总是会遇到问题 #2。没有完美的方法来解决这个难题。 This MTF pivot script 展示了如何回顾图表的过去柱,以查找 HTF 中标识的枢轴值的最接近值。这是一种妥协,可能并不适用于所有情况。

    【讨论】:

    • 感谢您的指标。很棒,就像 ZigZag 一样显示最后的低点,并且在 1s 图表中使用正确的设置。我想我可以让它在我的策略中发挥作用。再次非常感谢,这将为我节省一些钱。
    猜你喜欢
    • 2022-10-02
    • 1970-01-01
    • 2020-04-18
    • 2022-09-25
    • 2021-06-08
    • 2021-08-28
    • 2017-01-20
    • 1970-01-01
    • 2019-03-02
    相关资源
    最近更新 更多