1

I am trying to create an indicator in tradingview that plot the high of the day and low of the day. The below mentioned pine code is working and indicator is plotting the line expected.

//@version=5
indicator(title="HOD-LOD", shorttitle="Current Day High and Low", overlay=true)

[dh,dl] = request.security(syminfo.ticker, "D", [high,low], lookahead=barmerge.lookahead_on)

plot(dh, title="HOD",  color=color.rgb(90, 208, 153),  linewidth=2, trackprice=true)
plot(dl, title="LOD",  color=color.rgb(207, 64, 64),  linewidth=2, trackprice=true)

I have tried using the text and shape in pine script version5 but then I need to remove the trackprice=true without which the tracking the new high and new low is not possible. PFB for the excepted output image. Any help would be appreciated.

[https://www.tradingview.com/pine-script-docs/en/v5/concepts/Text_and_shapes.html#labels]

enter image description here

Iamlearner
  • 13
  • 3

1 Answers1

0

You should try to print label only when your high of the day change :

if dh[1] != dh
    label.new(bar_index,dh,str.tostring(dh))
if dl[1] != dl
    label.new(bar_index,dl,str.tostring(dl))

With this code, you will have this type of result : enter image description here

G.Lebret
  • 2,826
  • 2
  • 16
  • 27
  • when we use the label, it is not the label on the the exact candle which is high and the candle which made the low. – Iamlearner Nov 23 '22 at 05:22
  • I don't understand your comment. Does this answer helps you ? – G.Lebret Nov 23 '22 at 16:06
  • your solution partially worked as it is not plotting the high of the day and low of the day correctly. – Iamlearner Nov 25 '22 at 15:27
  • @Iamlearner the code I provide you explain you how to draw a label at the level you calculate in your code (aka dh and dl). What is missing you ? – G.Lebret Nov 26 '22 at 01:59