pinescript“未申报的标识符”
我得到了未宣布的“ 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.您告诉您的脚本使用
d
,当您的脚本不知道d
的意思是什么时,因为您在两个不同的范围中使用d
。在使用
Y2,Y1,Y1_D
之前,声明(并初始化)它。P.EX。
应该解决它。
You are telling your script to use
d
, when your script does not know whatd
means, because you are usingd
in two different scopes.Declare (and initialize) it, just like you did with
y2, y1, y1_d
, before you use it.p.ex.
That should fix it.