Andrew Martin
Andrew Martin

Reputation: 37

trying to find barssince a pivot high

Just wondering if anyone can help me get this idea working? Trying to figure out how many bars since the last 3 pivot highs respectively. just thought I could do a barssince the value of the high was at that value.....doesn't work :(.

................................................

left = input(15,"left")

right = input(15,"right")

pivot_high = pivothigh(high,left,right)

high1 = valuewhen(pivot_high, high[right], 2)

high2 = valuewhen(pivot_high, high[right], 1)

high3 = valuewhen(pivot_high, high[right], 0)

bh1 = barssince(high == high1)

bh2 = barssince(high == high2)

bh3 = barssince(high == high3)

plot(bh1,"bars since high 1")

plot(bh2,"bars since high 2")

plot(bh3,"bars since high 3")

Upvotes: 1

Views: 708

Answers (1)

rumpypumpydumpy
rumpypumpydumpy

Reputation: 3833

You can accomplish this by creating your own bool variable to track the pivot condition at the time of the pivot. You can use barssince() to obtain the last occurrence or valuewhen() to get previous occurrences.

bool pvh = high[1] > high[0] and high[1] > high[2]

int sincepvh = barssince(pvh)

sincepvh1st = bar_index - valuewhen(pvh, bar_index, 0)
sincepvh2nd = bar_index - valuewhen(pvh, bar_index, 1)
sincepvh3rd = bar_index - valuewhen(pvh, bar_index, 2)

Also if you wanted the bar of the peak or, for example the high of the peak :

sincepvh1st = bar_index - valuewhen(pvh, bar_index[1], 0)
pvh1high = valuewhen(pvh, high[1], 0)

Upvotes: 2

Related Questions