![](/img/trans.png)
[英]Problem with changing a global variable in a onclick function in javascript / php
[英]Plot on higher time frame. Security, mutable variable, global variable, function problem
我也在尝试将 plot 从 15 分钟到 Daily 的相同形状。 这是 plot 的代码,在 15 分钟内运行良好;
if crossover(s3K,s3D) and s3K<25 and (s4K-s4D<3 and s4K-s4D>-3) and s4K<35//or s4D-s4K>0 and s4D-s4K<1 and s4K<50 and s1K<40
rwCross:=true
plotshape(rwCross, style = shape.arrowup, location = location.belowbar, color=color.yellow, size=size.small)
但是我试过每天给 plot ;
rwCrossDaily = security(syminfo.tickerid,'D', rwCross)
plotshape(rwCrossDaily, style = shape.arrowup, location = location.belowbar, color=color.yellow, size=size.small)
这给了我可变变量错误。 所以我尝试使用 function 来绕过它;
rwCross_func() =>
if crossover(s3K,s3D) and s3K<25 and (s4K-s4D<3 and s4K-s4D>-3) and s4K<35//or s4D-s4K>0 and s4D-s4K<1 and s4K<50 and s1K<40
rwCross:=true
rwCrossDaily = security(syminfo.tickerid,'D', rwCross_func())
但现在它告诉我“无法修改 function 中的全局变量‘rwCross’。” 请帮忙!
这里最好的解决方案和最干净的解决方案是以最简单的形式从您的条件中提取一个布尔值:
rwCross = crossover(s3K,s3D) and s3K<25 and (s4K-s4D<3 and s4K-s4D>-3) and s4K<35//or s4D-s4K>0 and s4D-s4K<1 and s4K<50 and s1K<40
没有 if,rwCross 自然会变为 true。 这样我们就不需要有任何可变的东西,尽管对于我们必须的情况有更多的解决方案......
干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.