Reputation: 380
I have been trying to do a simple condition where if a condition is higher than another condition than plot on the top of the bar. On this case I am finding Pivot with Lower High and Lower Low. I am trying to implement a way to find Lower Low that are higher than the previous Lower Low than i will plot something on top of the bar (LLHigher)
//@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="")
Now for some reason the condition doesn't seem to work all the time and I am unsure what I am doing wrong Example
Thanks
Upvotes: 0
Views: 2411
Reputation: 3818
There is no bug Andre and no need to open the support ticket.
First, when you compare the value of previous low in this line:
llhigherprevious = valuewhen(ll, low[1], 1) < valuewhen(ll, low[1], 0)
you have to note that variable ll and [LL] plot on the chart is not the same. plot([LL]) use 2 bool conditions: ll and pl
plotchar(ll and pl, title="LL", location=location.belowbar, char = "", color=color.green, transp=75, text="[LL]")
If you'll plot the ll variable that you use to find the llhigherprevious you'll see this:
So when the new point of pl and ll is found it is comparing ll's low with the previous ll's low, not with [LL]'s low.
Solution: add a LL bool variable and use it's value in 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)
Upvotes: 1
Reputation: 470
woah super weird...do a replay and you'll see what's happening. For some reason Pine is removing a LL in between. My guess...some kind of Pine Script bug. I'd report it to Support.
Upvotes: 0