sku
sku

Reputation: 605

Looking for a way to restrict Tradingview from plotting previous day high, low lines only for current day

New to Pinescript and Tradingview. I have this issue where I use a custom indicator script to plot previous day high and previous day low lines. The problem is I have no way to restrict it to plot only for today and not the entire chart which is very annoying to see. Please take a look to see if you can help me out. Thanksenter image description here Here is the code -->

study(title="Previous Day High and Low", shorttitle="Previous Day High and Low", overlay=true)
D_High = security(tickerid, 'D', high[1]) 
D_Low = security(tickerid, 'D', low[1]) 
D_Close =  security(tickerid, 'D', close[1]) 
D_Open =  security(tickerid, 'D', open[1]) 


plot(isintraday ? D_High : na, title="Daily High",style=line, color=green,linewidth=2) 
plot(isintraday ? D_Low : na, title="Daily Low",style=line, color=red,linewidth=2)

Upvotes: 0

Views: 2000

Answers (1)

André
André

Reputation: 470

You'll want to use v4's line.new() to draw your lines instead of plot(). This way, you can draw your lines from and to specific points of your choosing (such as the high or low from x days ago).

You'll need two lines (just like your two plots), one for the highs and one for the lows. And you'll want to either 1) only draw them if you're on the last bar, or 2) draw them and update the points as you go.

Here's an article with some examples on line.new(): https://marketscripters.com/how-to-use-pine-scripts-v4-line-function/

Upvotes: 1

Related Questions