如何根据以前的情节有条件地绘制松树脚本



我正在制作简单的摆动高点和摆动低查找器/警报,一切都很好,除了在很多情况下摆动高点之后出现另一个摆动高点。

逻辑很简单 - 如果之前的两根蜡烛低于这根蜡烛,并且之后的两根蜡烛也较低,则定义摆动高点

我想要实现的是,只有在以前的情节没有摆动高的情况下,才绘制高摆动。

这将是代码

//@version=4
study("Swing Point Finder")
hhCondition = high[4] < high[2] and high[3] < high[2] and high[1] < high[2] and high < high[2]
llCondition = low[4] > low[2] and low[3] > low[2] and low[1] > low[2] and low > low[2]

plot(hhCondition ? 1 : 0, "Swing High found", color.green, offset = -2)
plot(llCondition ? 1 : 0, "Swing Low found", color.red, offset = -2)

也许你可以尝试这样的事情:

plot(hhCondition and not hhCondition[1] ? 1 : 0, "Swing High found", color.green, offset = -2)

是的,很好的收获,我在编写的多个脚本中遇到了同样的问题。

我在这里建议创建一个跟踪所有枢轴点的变量。

isPivot == hhCondition or llCondition

然后,在新的枢轴上,将其与上一个枢轴进行比较。 例如这样的内容:

plotThisHigh = hhCondition
if (hhCondition)
sameDirection = valuewhen(isPivot, hhCondition, 0)
plotThisHigh := sameDirection ? false : true

复制此内容以检查以前的枢轴低点。 我建议使用不同的变量进行绘图(plotThisHigh而不是重新分配hhCondition(,因为如果连续有三个hh条件(中间没有llConditions(,那么如果你重新分配hhCondition逻辑将不再有效。 这有意义吗?

如果您需要,我在此博客文章中写了更多详细信息...希望对您有所帮助 https://marketscripters.com/how-to-work-with-pivots-in-pine-script/

最新更新