How can I get the last price in Pine Script?
That number.
I need it as a float instead of series float.
Doing this:
//@version=5
indicator(title="EURUSD")
inputEURUSD = input.symbol("EURUSD")
EURUSDprice = request.security(inputEURUSD, timeframe.period, close)
lastPriceEURUSD = EURUSDprice[0]
EURUSDtoZero = EURUSDprice - 1.09107 // translate on y-axis manually
EURUSDminusLastPrice = EURUSDprice - lastPriceEURUSD // attempt to translate on y-axis automatically
plot(series=EURUSDprice, color=color.red, title="EURUSD", linewidth=1, style=plot.style_line, trackprice=false)
plot(series=lastPriceEURUSD, color=color.green, title="EURUSD[0]", linewidth=1, style=plot.style_line, trackprice=false)
plot(series=EURUSDtoZero, color=color.blue, title="EURUSD-1.09107", linewidth=1, style=plot.style_line, trackprice=false)
plot(series=EURUSDminusLastPrice, color=color.white, title="EURUSD-EURUSD[0]", linewidth=1, style=plot.style_line, trackprice=false)
Gives you a flat line. As it should:
But if:
priceEURUSD[0]
gives you a series, than, how can I get that number as a float instead of series float, and use it to translate the priceline downwards by that many units on y-axis?
UPDATE:
I need it, basically, to represent varying degrees of movement in a single graph. Take these boring lines, for example:
They're meaningless. But with a bit of manual translation on the y-axis, they start to take a meaningful shape:
So an automatic way to translate them by their last price, has to be found somewhere.
Even more so - the more converging you can get them, the more pronounced and meaningful they become.
ANSWER:
ta.tsi(USDEURprice, 10, 10)
Above graph shows, the upper lines, been translated manually and the bottom lines, been done with ta.tsi()
The resolution can be controlled with the "10, 10" (the smaller, the better resolution)