当两个值比较时,PineScript条件不起作用

时间:2020-07-13 07:41:06

标签: pine-script

我一直在尝试做一个简单的条件,如果一个条件高于另一个条件而不是在柱形图的顶部绘制。 在这种情况下,我发现具有较低高位和较低低位的数据透视。我正在尝试实现一种方法,以找到比之前的“低位低点”更高的“低位低点”,该高度低于我会在柱线(LLHigher)上方绘制一些内容

视觉解释 enter image description here

//@version=4
study("Swing Low",overlay = true)


var s = 0.0
/// Pivots
leftbars = input(title="LeftBars", defval=1)
rightbars = input(title="Rightbars", defval=1)

HighOfCandle =  high
LowOfCandle = low
CloseOfCandle = close
OpenOfCandle = open
SizeOfCandle = abs(HighOfCandle-LowOfCandle)
pl = ((LowOfCandle > LowOfCandle[1]) and  (LowOfCandle[1] < LowOfCandle[2]))
//plotchar(pl, title="Pivot Low",  location=location.abovebar, char = "", color=color.green, transp=75, text="[P]", offset=-rightbars, size=size.auto)

ll = valuewhen(pl, low[1], 1) > valuewhen(pl, low[1], 0) 
plotchar(ll and pl, title="LL",  location=location.belowbar, char = "", color=color.green, transp=75, text="[LL]", offset=-rightbars, size=size.auto)

llhigherprevious = valuewhen(ll, low[1], 1) < valuewhen(ll, low[1], 0)
plotchar( llhigherprevious and pl and ll , text="LLhigher" ,color=color.orange,location=location.abovebar,transp=0,offset=-1,char="")

现在,由于某种原因,这种情况似乎并非一直都有效,而且我不确定自己在做什么错 例子

enter image description here

谢谢

2 个答案:

答案 0 :(得分:1)

Andre没有错误,也不需要打开支持记录。

首先,当您比较此行中的先前低点的值时:

llhigherprevious = valuewhen(ll, low[1], 1) < valuewhen(ll, low[1], 0)

您必须注意,图表上变量ll和[LL]的图不相同。 plot([LL])使用2个布尔条件:ll和pl

plotchar(ll and pl, title="LL",  location=location.belowbar, char = "", color=color.green, transp=75, text="[LL]")

如果要绘制用于查找llhigherprevious的ll变量,则会看到以下内容: ll variable plot

因此,当找到pl和ll的新点时,它会将ll的低点与之前的ll的低点进行比较,而不是与[LL]的低点进行比较。

解决方案:添加一个LL bool变量,并在llhigherprevious中使用它的值:

ll = valuewhen(pl, low[1], 1) > valuewhen(pl, low[1], 0) 

LL = ll and pl
plotchar(LL, title="LL",  location=location.belowbar, char = "", color=color.green, transp=75, text="[LL]")//, offset=-rightbars, size=size.auto)

llhigherprevious = valuewhen(LL, low[1], 1) < valuewhen(LL, low[1], 0)
plotchar( llhigherprevious and pl and ll , text="LLhigher" ,color=color.orange,location=location.abovebar,transp=0, char="" )//,offset=-1)

enter image description here

答案 1 :(得分:0)

哇,好奇怪...重播,您会发现发生了什么。 由于某种原因,Pine会删除两者之间的LL。我的猜测...某种派恩脚本错误。我会报告给支持部门。

enter image description here

enter image description here