所以我在笔录上编了一个指示符。在编写同一段代码的两种方法之间,嵌套if语句的行为似乎不同。
crossover = crossover(tradeEntrySource, ind)
crossunder = crossunder(tradeEntrySource, ind) // use statement directly
longStopLossCheck := if (not crossover)
if (crossunder(tradeEntrySource, ind))
true
else
falsevs
// precalculate and use variable
longStopLossCheck := if (not crossover)
if (crossunder)
true
else
falseplot(series=longStopLossCheck?3:2, title="longStopLossCheck", color = color.red)
plot(series=crossunder?2:1, title="crossunder", color = color.blue)
plot(series=crossover?1:0, title="crossover", color = color.green)


第一个图像显示直接使用语句时返回的值,第二个图像显示使用变量时返回的值。
我似乎不明白为什么我会看到不同的价值观/行为。对于为什么会发生这种事,有什么见解吗?提前感谢!
发布于 2020-08-13 12:16:50
需要在每个条形图上执行像crossover()这样的函数才能返回正确的结果,当从条件块中调用它们时,情况就不一样了,因为条件块阻止它们在每个条形图上执行。在进入if结构之前对这些函数进行预评估是解决方案。
请参阅关于该主题的松树用户手册,以及在这个主题上可能更容易理解的来自PineCoders常见问题的文章。
公开:这个答案中的链接指向一个PineCoders常见问题条目。我是PineCoders社区的一员,我很可能写了FAQ条目。PineCoders是一个由TradingView支持的志愿松树编解码者团体,PineCoders的网站具有严格的教育性.TradingView和PineCoders都不能从向pinecoders.com发送流量中获得经济上的好处,而且该站点也不包含任何附属/推荐链接。
https://stackoverflow.com/questions/63335679
复制相似问题