-1

How can I get the last price in Pine Script?

enter image description here

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: enter image description here enter image description here 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:

enter image description here

They're meaningless. But with a bit of manual translation on the y-axis, they start to take a meaningful shape:

enter image description here

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:

enter image description here

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)

Nils Riga
  • 90
  • 2
  • 15

2 Answers2

1

I hope I understood your idea, You can use ta.tsi true strength index. It uses moving averages of the underlying momentum of a financial instrument. chart for true strength index indicator

//@version=5
indicator(title="EURUSD")

fast=9
slow=9

inputEURUSD = input.symbol("EURUSD")
price = request.security(inputEURUSD, timeframe.period, close)
EURUSDtoZero = price - 1.09107 // translate on y-axis manually
EURUSDminusLastPrice = price - price[close] // attempt to translate on y-axis automatically



EURUSDprice_tsi = ta.tsi(price, slow, fast)
lastPriceEURUSD_tsi = ta.tsi(price[close], slow, fast)
EURUSDtoZero_tsi = ta.tsi(EURUSDtoZero, slow, fast)
EURUSDminusLastPrice_tsi = ta.tsi(EURUSDminusLastPrice, slow, fast)

plot(EURUSDprice_tsi,color=color.red, title="EURUSD", linewidth=1, style=plot.style_line, trackprice=false) 
plot(lastPriceEURUSD_tsi, color=color.green, title="EURUSD[0]", linewidth=1, style=plot.style_line, trackprice=false) 
plot(EURUSDtoZero_tsi, color=color.blue, title="EURUSD-1.09107", linewidth=1, style=plot.style_line, trackprice=false) 
plot(EURUSDminusLastPrice_tsi,color=color.red, color=color.white, title="EURUSD-EURUSD[0]", linewidth=1, style=plot.style_line, trackprice=false) 
Mazen Abduallah
  • 124
  • 1
  • 4
0

EURUSDprice is the number. [0] is not needed and adds nothing. You can use EURUSDprice in other calculations. Last price is [1] as in one bar ago...

Bjorgum
  • 2,054
  • 2
  • 4
  • 11
  • So far I have understood, yes. But you see. In the graph. When I try to translate the priceline downwards on y-axis, automatically, by the EURUSDprice or EURUSDprice[0] - I get a flat line. – Nils Riga Mar 13 '22 at 18:04
  • 1
    indicator(title="EURUSD", precision = 4) increasing the precision of the numbers you will see you do not get zero, except for the white line because you are subtracting a number from itself. EURUSDprice is equal to EURUSDprice [0]. – Bjorgum Mar 13 '22 at 18:10
  • Ok. Tried precision = 10. Great tip! But how does that help for translating a priceline downwards on y-axis? – Nils Riga Mar 13 '22 at 18:15
  • you can add and subtract values as you wish? I think the question has been answered though. You have the number as a float and as long as you dont subtract it from itself it will not be zero – Bjorgum Mar 13 '22 at 18:21
  • No. You don't understand. Not at all. I didn't want noise in the graph and my question. My goal is to make several price lines converge to zero, so that tradingview visualization engine would represent the past price differences in – Nils Riga Mar 13 '22 at 18:23
  • a meaningful way, relative to one another, instead of themselves. For that I need to be able to translate each priceline on y-axis by its current price. – Nils Riga Mar 13 '22 at 18:24
  • But all that is not, in essence, relevant to just the thing, that I can translate the line on y-axis by a number if I write it manually (1.09107), but the line flatlines, if I do it automatically. So how can I get that number as a float instead of a series float? – Nils Riga Mar 13 '22 at 18:25
  • tradingview API? Scraping the webpage? I bet not. But idk – Nils Riga Mar 13 '22 at 18:26