I am trying to write a pine script where an asset's price line is plotted, and the line's colour is either green or red depending on whether the relevant day's close is above or below the latest close.
I have code that works providing I hard code the most recent close price to a variable e.g. 10178 in my example below.
series = input(close, title="Source")
last_price = 10178
plot(series, color=last_price > close ? color.green : color.red)
But is there a way in Pine Script to automatically assign the latest close price?
I've tried close[0] but that appears to be an array of every day's close price (and so returns red for every day) but what I need is a single value.