How do i find the latest HH pivot point and latest LL pivot point?

Viewed 286

I can't seem to find a way to check for the latest HH or LL pivot point if the latest HH pivot or LL pivot is >10 bars away from the live bar.

I am looking for a variabel checkpoint if the latest HH pivot point is "Bullish" or "Bearish" and vice versa for the latest LL pivot point.

prd = input.int(defval=10, title='Pivot Point Period', minval=10, maxval=50)  //How many pivot points. Lower value results in more points.

var float ph = na
var float pl = na
ph := ta.pivothigh(prd, prd)
pl := ta.pivotlow(prd, prd)

var float last_ph = na
var float last_pl = na

pivotTrendHH = ph > last_ph ? "Bullish" : "Bearish"
pivotTrendLL = pl > last_pl ? "Bullish" : "Bearish"


ph_color = ph > last_ph ? color.green : color.red
pl_color = pl > last_pl ? color.green : color.red

if (ph) //If x days ago was a pivot point
    label.new(bar_index-prd, ph, pivotTrendHH, yloc=yloc.price, color=ph_color) //NOTE: bar_index-prd, becuse it occured x days ago
    last_ph := ph //Saves price data
if (pl)
    label.new(bar_index-prd, pl, pivotTrendLL, yloc=yloc.price, color=pl_color) 
    last_pl := pl //Saves price data
0 Answers
Related