Reputation: 1
How can I use older close rate in my Pine script code?
//@version=5
indicator('FRG 1', overlay=true)
L_close = close[2]
hline(L_close)
Error: Cannot call 'hline' with argument 'price'='L_close'. An argument of 'series float' type was used but a 'input float' is expected
Upvotes: 0
Views: 277
Reputation: 11
If you want to draw a floating value I would also go with plot, but if you want anything other than a continuous line you will have to do some more setup.
As I'm not sure what you're trying to achieve exactly (are you trying to draw the horizontal line for one bar under specific conditions, or do you want the line for the previous close for every candle?), I'll give an example from one of my scripts:
plot(strategy.position_size != 0 ? tradeStopPrice : na, title = "Trade Stop Price", color = color.red, style = plot.style_linebr)
There's an if clause in there that determines when it will plot and when it won't. If I am in a trade, it'll plot the trade stop price in red, if I am not it won't plot anything.
Then the "style = plot.style_linebr" means that it won't fill in empty parts (na) to try to make a continuous line (try it out without it to see the difference)
Depending on what you want to achieve you can fiddle with this a bit.
Upvotes: 0
Reputation: 1961
The error says that you cannot use series
variable. Function hline()
accepts only constants (input
values and literals), while close
value is changing trough the bars, so horizontal line cannot be plotted.
So you need to use plot
function instead:
//@version=5
indicator('FRG 1', overlay=true)
L_close = close[2]
plot(L_close)
https://www.tradingview.com/pine-script-docs/en/v5/concepts/Plots.html
Upvotes: 0