Blaž Hrovat
Blaž Hrovat

Reputation: 11

How to connect Pivot Points H/L with a line in TradingView Pine?

I found script for pivot H/L looks like this:

enter image description here

But I want that the H and L are connected with a line, like this:

enter image description here

And here is script:

study(title="Pivot Points H/L", shorttitle="Pivots H/L", overlay=true)
len = input(14, minval=1, title="Length")
    //The length defines how many periods a high or low must hold to be a "relevant pivot"

h = highest(len)
    //The highest high over the length
h1 = dev(h, len) ? na : h
    //h1 is a pivot of h if it holds for the full length
hpivot = fixnan(h1)
    //creates a series which is equal to the last pivot

l = lowest(len)
l1 = dev(l, len) ? na : l
lpivot = fixnan(l1)
    //repeated for lows

plot(hpivot, color=blue, linewidth=2, offset= -len+1)
plot(lpivot, color=purple, linewidth=2, offset= -len+1)
//plot(h1, color=black, style=circles, linewidth=4, offset= -len+1)
//plot(l1, color=black, style=circles, linewidth=4, offset= -len+1)

Thank you.

Upvotes: 0

Views: 4255

Answers (2)

Mikeyy
Mikeyy

Reputation: 285

Without going deep into code, you can produce your second picture with pine code.

You should record highs in one variable, and record signal that pivot is active in another. When pivot active code triggers you can plot with offset.

Lets say you are searching for pivot in price with 2 right candles lower value. After 2 candles you will get signal that 2 candles before, you had your pivot and then you should execute something like this:

plot(is_pivoth ? pivot_high_price : na, location=location.absolute, offset=-2)

Upvotes: 1

Jos
Jos

Reputation: 1852

But i will like that the H and L will be connected with this line.

It's unfortunately at this time not possible to code trend lines in TradingView Pine.

A TradingView representative said here in February 2017 that making trend lines with scripts is on the roadmap. But he didn't say when that feature is possible. So it might be a while, or it might become available next month.


As a work around you can plot a line with the plot() function. That, unfortunately, has the disadvantage that the line appears over each bar and cannot be 'turned off'.

(I see from your code that you already used plot() earlier, so I think this is something you already tried and didn't find a good solution.)

Upvotes: 0

Related Questions