繁体   English   中英

不能使用可变变量作为 request.security 的参数 function

[英]Cannot use a mutable variable as an argument of the request.security function

我写了一段代码,以便找到如下所示的特定情况; (如果 2 种情况的交叉/交叉在 15 分钟的蜡烛中为真,则在 5 分钟内找到具有相同情况的蜡烛。

这是代码:

//@version=5
indicator(title=" TRY ___???", overlay=true)

//StochRSI

smoothK = input.int(3, "K", minval=1)
smoothD = input.int(3, "D", minval=1)
lengthRSI = input.int(14, "RSI Length", minval=1)
lengthStoch = input.int(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)
//plot(k, "K", color=#2962FF)
//plot(d, "D", color=#FF6D00)
//h0 = hline(80, "Upper Band", color=#787B86)
//h1 = hline(20, "Lower Band", color=#787B86)
//fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")

//FISHER

len = input.int(9, minval=1, title="Length")
high_ = ta.highest(hl2, len)
low_ = ta.lowest(hl2, len)
round_(val) => val > .99 ? .999 : val < -.99 ? -.999 : val
value = 0.0
value := round_(.66 * ((hl2 - low_) / (high_ - low_) - .5) + .67 * nz(value[1]))
fish1 = 0.0
fish1 := .5 * math.log((1 + value) / (1 - value)) + .5 * nz(fish1[1])
fish2 = fish1[1]
//hline(1.5, "1.5", color=#E91E63)
//hline(0.75,"0.75", color=#787B86)
//hline(0, "0", color=#E91E63)
//hline(-0.75, "-0.75", color=#787B86)
//hline(-1.5, "-1.5", color=#E91E63)
//plot(fish1, color=#2962FF, title="Fisher")
//plot(fish2, color=#FF6D00, title="Trigger")


//BUY
[fish1_15,fish2_15] = request.security('','15',[fish1,fish2])
[k_15,d_15] = request.security('','15',[k,d])

[fish1_5,fish2_5] = request.security('','5',[fish1,fish2])
[k_5,d_5] = request.security('','5',[k,d])

buy_signal = if ta.crossover(fish1_15,fish2_15) and ta.crossover(k_15,d_15)
    ta.crossover(fish1_5,fish2_5) and ta.crossover(k_5,d_5)
else
    false
plotshape(buy_signal, style= shape.labelup, location= location.belowbar ,color= color.green,  textcolor= color.white, text = "buy" )

//SELL

sell_signal = if ta.crossunder(fish1_15,fish2_15) and ta.crossunder(k_15,d_15)
    ta.crossunder(fish1_5,fish2_5) and ta.crossunder(k_5,d_5)
else
    false
plotshape(sell_signal, style= shape.labeldown, location= location.abovebar ,color= color.red,  textcolor= color.white, text = "sell" )

这是错误://第 41 行:无法使用可变变量作为 request.security function 的参数。

我想知道是否有人可以帮助我解决这个问题。

那些线

value = 0.0
value := round_(.66 * ((hl2 - low_) / (high_ - low_) - .5) + .67 * nz(value[1]))
fish1 = 0.0
fish1 := .5 * math.log((1 + value) / (1 - value)) + .5 * nz(fish1[1])
fish2 = fish1[1]

在逻辑上是不正确的。 可能你打算这样编码:


v1 = round_(.66 * ((hl2 - low_) / (high_ - low_) - .5) + .67) 
value = v1 * nz(v1[1])
f1 = .5 * math.log((1 + value) / (1 - value)) + .5
fish1 = f1 * nz(f1[1])
fish2 = fish1[1]

至于错误,首先声明然后使用:=重新分配的变量称为可变变量 可变变量可以在脚本的任何 scope 内更改。 security function 创建了另一个图表 scope,“吸入”脚本中声明的所有变量。 它不能“吸收”可变变量,因为它们的值可以在其他地方更改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM