Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
418 views
in Technique[技术] by (71.8m points)

Pine Script: Draw hline of the lowest low in the last 10 bars

I would like to get the lowest low of the last 10 bars in TradingView. I have tried this:

if(barstate.islast)
    bottom = lowest(10)
    hline(bottom)

But it gives me the error 'Cannot call hline with series[float]'. Since bottom is apparently a series, I've also tried referencing position 0 of bottom like this:

if(barstate.islast)
    bottom = lowest(10)
    hline(bottom[0])

This returns the same error. It still thinks I'm passing a series, but I am trying to pass a float. Any ideas what I am doing wrong? I need to be able to do calculations on multiple bars and draw lines based on those calculations.

question from:https://stackoverflow.com/questions/65907810/pine-script-draw-hline-of-the-lowest-low-in-the-last-10-bars

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This will plot what you're asking:

//@version=4
study("Line", overlay=true)

bars_back  = input(10)
draw_hline = input(true)

var line myLine = line.new(na, na, na, na, extend = draw_hline ? extend.both : extend.right, color=color.yellow, style=line.style_dashed, width=2)

ll = lowest(bars_back)
lb = lowestbars(bars_back) // returns a negative offset number

line.set_xy1(myLine, bar_index + lb, ll)
line.set_xy2(myLine, bar_index,      ll)

Example:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...