Hi,
I use below code to print HH HL LL and LH in tradingview. I am looking for same in PRT. I have seen some topics here but mostly allow me to print e.g. the value but is it possible to determine HH HL LL and LH in PRT e.g. using Arrays?
Andrea, Ale, anyone? Appreciate your helping hands. Thanks.
//Only prints HH HL LL LH
//@version=3
study("HH HL LH LL", overlay =true)
lb = input(3, title="Left Bars", minval = 1)
rb = input(6, title="Right Bars", minval = 1)
mb = lb + rb + 1
ph = iff(not na(high[mb]), iff(highestbars(high, mb) == -lb, high[lb], na), na) // Pivot High
pl = iff(not na(low[mb]), iff(lowestbars(low, mb) == -lb, low[lb], na), na) // Pivot Low
hl = na
hl := iff(ph, 1, iff(pl, -1, na)) // Trend direction
zz = na
zz := iff(ph, ph, iff(pl, pl, na)) // similar to zigzag but may have multiple highs/lows
zz :=iff(pl and hl == -1 and valuewhen(hl, hl, 1) == -1 and pl > valuewhen(zz, zz, 1), na, zz)
zz :=iff(ph and hl == 1 and valuewhen(hl, hl, 1) == 1 and ph < valuewhen(zz, zz, 1), na, zz)
hl := iff(hl==-1 and valuewhen(hl, hl, 1)==1 and zz > valuewhen(zz, zz, 1), na, hl)
hl := iff(hl==1 and valuewhen(hl, hl, 1)==-1 and zz < valuewhen(zz, zz, 1), na, hl)
zz := iff(na(hl), na, zz)
findprevious()=> // finds previous three points (b, c, d, e)
ehl = iff(hl==1, -1, 1)
loc1 = 0.0, loc2 = 0.0, loc3 = 0.0, loc4 = 0.0
xx = 0
for x=1 to 1000
if hl[x]==ehl and not na(zz[x])
loc1 := zz[x]
xx := x + 1
break
ehl := hl
for x=xx to 1000
if hl[x]==ehl and not na(zz[x])
loc2 := zz[x]
xx := x + 1
break
ehl := iff(hl==1, -1, 1)
for x=xx to 1000
if hl[x]==ehl and not na(zz[x])
loc3 := zz[x]
xx := x + 1
break
ehl := hl
for x=xx to 1000
if hl[x]==ehl and not na(zz[x])
loc4 := zz[x]
break
[loc1, loc2, loc3, loc4]
a = na, b = na, c = na, d = na, e = na
if not na(hl)
[loc1, loc2, loc3, loc4] = findprevious()
a := zz
b := loc1
c := loc2
d := loc3
e := loc4
_hh = zz and (a > b and a > c and c > b and c > d)
_ll = zz and (a < b and a < c and c < b and c < d)
_hl = zz and ((a >= c and (b > c and b > d and d > c and d > e)) or (a < b and a > c and b < d))
_lh = zz and ((a <= c and (b < c and b < d and d < c and d < e)) or (a > b and a < c and b > d))
plotshape(_hl, text="HL", title="Higher Low", style=shape.labelup, color=lime, textcolor=black, location=location.belowbar, transp=0, offset = -lb)
plotshape(_hh, text="HH", title="Higher High", style=shape.labeldown, color=lime, textcolor=black, location=location.abovebar, transp=0, offset = -lb)
plotshape(_ll, text="LL", title="Lower Low", style=shape.labelup, color=red, textcolor=white, location=location.belowbar, transp=0, offset = -lb)
plotshape(_lh, text="LH", title="Lower High", style=shape.labeldown, color=red, textcolor=white, location=location.abovebar, transp=0, offset = -lb)
Regards,
Ash