Pitt
Pitt

Reputation: 29

How do i delete all labels after the latest 2?

I would like to adjust the standard tradingview "Pivot Points High Low" indicator to only show the latest 2 HH pivot points and the latest 2 LL pivot points.

Can someone help me with this problem?

gr="LENGTH LEFT / RIGHT"
leftLenH = input.int(title="Pivot High", defval=10, minval=1, inline="Pivot High",group=gr)
rightLenH = input.int(title="/", defval=10, minval=1, inline="Pivot High",group=gr)
colorH = input(title="", defval=#E3EFFD, inline="Pivot High",group=gr)

leftLenL = input.int(title="Pivot Low", defval=10, minval=1, inline="Pivot Low", group=gr)
rightLenL = input.int(title="/", defval=10, minval=1, inline="Pivot Low",group=gr)
colorL = input(title="", defval=#E3EFFD, inline="Pivot Low",group=gr)

ph = ta.pivothigh(leftLenH, rightLenH)
pl = ta.pivotlow(leftLenL, rightLenL)

drawLabel(_offset, _pivot, _style, _color) =>
    if not na(_pivot)
        label.new(bar_index[_offset], _pivot, str.tostring(_pivot, format.mintick), style=_style, color=_color, textcolor=#131722)

drawLabel(rightLenH, ph, label.style_label_down, colorH)
drawLabel(rightLenL, pl, label.style_label_up, colorL)



Upvotes: 0

Views: 737

Answers (1)

Bjorgum
Bjorgum

Reputation: 2310

A very easy and simple way is to change the maximum number of labels in the indicator() header. Try replacing the header function with the following:

indicator("Pivot Points High Low", shorttitle="Pivots HL", overlay=true, max_labels_count=2)

Cheers, and best of luck with your trading and coding

Upvotes: 2

Related Questions