首页 > 解决方案 > 之后传递的一系列数据如何评估?:

问题描述

我是 pinescript 的新手,我试图了解事情是如何工作的,我正在努力完全理解 iff 语句 (?:) 以及当它们在 ?: 之后传递时它如何评估一系列数据。

higher_than = high > close
x = higher_than ? 1 : 0
b = x > 0 ? higher[2]: na

x 被评估为对于在higher_than 中为真的每个值被替换为1,如果一个值为假,它被替换为0。但是b 语句呢?这行得通吗?

对于 x 中优于零的每个值,用相同索引处的更高值替换它?

标签: pine-script

解决方案


这向您展示了如何调试脚本,以便您可以检查每个条的所有计算值。使用数据窗口进行调试非常有用。通过检查其中的值,您应该能够回答自己的问题。如果你不能,就这么说吧。

//@version=4
study("Debugging", "", true)
higher_than = high > close
x = higher_than ? 1 : 0
b = x > 0 ? high[2]: na
// This is a boolean so we plot a dot when it's true.
plotchar(higher_than, "higher_than", "•", location.top)
// This is a 0/1 value so we can't plot it on the chart because it will ruin the scale, so we plot it in the Data Window.
plotchar(x, "x", "", location.top)
// This value fits in the chart's price scale, so we can plot it directly on the chart. This plots the high from 2 bars ago.
plot(high[2], "high[2]")
// This also fits on the chart, but we use a different color and make the plot wider 
// and more transparent so the previous plot in the default blue can show through.
plot(b, "b", color.orange, 5, transp = 60)

在此处输入图像描述


推荐阅读