pinescript“未申报的标识符”

发布于 2025-01-23 23:23:57 字数 1547 浏览 0 评论 0原文

我得到了未宣布的“ D”错误。这是从带有警报的指示器中转换的。但是当我将它们放在电视上时,什么都不会发生。我似乎无法弄清楚。谁能为我提供此错误来帮助我吗?

strategy("My strategy",overlay=true,max_lines_count=500,max_bars_back=500)
h = input(8.,'Bandwidth')
src = input(close,'Source')
//----
n = bar_index
var ln = array.new_line(0) 
if barstate.isfirst
    for i = 0 to 499
        array.push(ln,line.new(na,na,na,na))
//----
float y2 = na
float y1 = na
float y1_d = na
//----
line l = na
label lb = na
if barstate.islast
    for i = 0 to math.min(499,n-1)
        sum = 0.
        sumw = 0.
        for j = 0 to math.min(499,n-1)
            w = math.exp(-(math.pow(i-j,2)/(h*h*2)))
            sum += src[j]*w
            sumw += w
        y2 := sum/sumw
        d = y2 - y1
        l := array.get(ln,i)
        line.set_xy1(l,n-i+1,y1)
        line.set_xy2(l,n-i,y2)
        line.set_color(l,y2 > y1 ? #ff1100 : #39ff14)
        line.set_width(l,2)
        
        if d > 0 and y1_d < 0
            label.new(n-i+1,src[i],'▲',color=#00000000,style=label.style_label_up,textcolor=#39ff14,textalign=text.align_center) 
            
            
        if d < 0 and y1_d > 0
            label.new(n-i+1,src[i],'▼',color=#00000000,style=label.style_label_down,textcolor=#ff1100,textalign=text.align_center) 
            
        y1 := y2
        y1_d := d
        

Buy = d > 0 and y1_d < 0
Sell = d < 0 and y1_d > 0

longCondition = Buy
if (longCondition)
    strategy.entry("Id", strategy.long)

shortCondition = Sell
if (shortCondition)
    strategy.close("Id")

I am getting an Undeclared identified 'd' error. This was converted from an indicator that had alerts. But when I had them in TV nothing would happen. I can't seem to figure this out. Can anyone assist me with this error?

strategy("My strategy",overlay=true,max_lines_count=500,max_bars_back=500)
h = input(8.,'Bandwidth')
src = input(close,'Source')
//----
n = bar_index
var ln = array.new_line(0) 
if barstate.isfirst
    for i = 0 to 499
        array.push(ln,line.new(na,na,na,na))
//----
float y2 = na
float y1 = na
float y1_d = na
//----
line l = na
label lb = na
if barstate.islast
    for i = 0 to math.min(499,n-1)
        sum = 0.
        sumw = 0.
        for j = 0 to math.min(499,n-1)
            w = math.exp(-(math.pow(i-j,2)/(h*h*2)))
            sum += src[j]*w
            sumw += w
        y2 := sum/sumw
        d = y2 - y1
        l := array.get(ln,i)
        line.set_xy1(l,n-i+1,y1)
        line.set_xy2(l,n-i,y2)
        line.set_color(l,y2 > y1 ? #ff1100 : #39ff14)
        line.set_width(l,2)
        
        if d > 0 and y1_d < 0
            label.new(n-i+1,src[i],'▲',color=#00000000,style=label.style_label_up,textcolor=#39ff14,textalign=text.align_center) 
            
            
        if d < 0 and y1_d > 0
            label.new(n-i+1,src[i],'▼',color=#00000000,style=label.style_label_down,textcolor=#ff1100,textalign=text.align_center) 
            
        y1 := y2
        y1_d := d
        

Buy = d > 0 and y1_d < 0
Sell = d < 0 and y1_d > 0

longCondition = Buy
if (longCondition)
    strategy.entry("Id", strategy.long)

shortCondition = Sell
if (shortCondition)
    strategy.close("Id")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一抹淡然 2025-01-30 23:23:57

d在for循环内部的本地范围中定义。您正在尝试在全球范围上访问它,该范围无法正常工作,因为它在全球范围中不可见。

d is defined in a local scope, inside the for loop. You are trying to access it on the global scope which will not work because it is not visible on the global scope.

橪书 2025-01-30 23:23:57

您告诉您的脚本使用d,当您的脚本不知道d的意思是什么时,因为您在两个不同的范围中使用d

在使用Y2,Y1,Y1_D之前,声明(并初始化)它。

P.EX。

int d = 0

应该解决它。

You are telling your script to use d, when your script does not know what d means, because you are using d in two different scopes.

Declare (and initialize) it, just like you did with y2, y1, y1_d, before you use it.

p.ex.

int d = 0

That should fix it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文