简体   繁体   English

Plot 在更高的时间范围内。 安全,可变变量,全局变量,function问题

[英]Plot on higher time frame. Security, mutable variable, global variable, function problem

I'm trying to plot the same shape from the 15 min onto the Daily as well.我也在尝试将 plot 从 15 分钟到 Daily 的相同形状。 This is the code to plot a shape on the 15 min which works fine;这是 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)

But to plot it on the daily i've tried;但是我试过每天给 plot ;

rwCrossDaily = security(syminfo.tickerid,'D', rwCross)
plotshape(rwCrossDaily, style = shape.arrowup, location = location.belowbar, color=color.yellow, size=size.small)

Which gives me the mutable variable error.这给了我可变变量错误。 So i tried using a function to get around it;所以我尝试使用 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())

But now it tells me I 'Cannot modify global variable 'rwCross' in function.'但现在它告诉我“无法修改 function 中的全局变量‘rwCross’。” Help please!请帮忙!

Best solution and cleanest solution here is to just make a bool out of your condition in its simplest form:这里最好的解决方案和最干净的解决方案是以最简单的形式从您的条件中提取一个布尔值:

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

rwCross will naturally become true without the if.没有 if,rwCross 自然会变为 true。 This way we do not need to have anything mutable, although there are more solutions for situations that we must...这样我们就不需要有任何可变的东西,尽管对于我们必须的情况有更多的解决方案......

Cheers!干杯!

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

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