最后交易价格 - "Last Price Line" 作为固定变量

Last traded Price - "Last Price Line" as a fixed variable

在 Tradingview 中,我想在 Pine Script 中获取股票的最后交易价格作为固定变量。在 Built 中,“关闭”是不够的,因为每个栏都会发生变化。作为交易视图图表中的示例,我们有“最后价格线”,它是最后交易价格的恒定线,如图所示

https://www.tradingview.com/x/5KVDU8h7/

Built-in变量'close'为最新成交价。这是一个以最后交易价格绘制黄色虚线的脚本,如您所见,它始终与 tradingview 绘制的默认“最后价格线”相同。如果您想访问之前柱的最后交易价格,您可以通过查找 close1..close[2]..close[n] 来实现,其中 n 是从当前柱返回的柱数。

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

var line _lpLine = line.new(0, 0, 0, 0, extend=extend.left, style=line.style_dashed, color=color.yellow)

_lastTradedPrice = close
line.set_xy1(_lpLine, bar_index-1, _lastTradedPrice)
line.set_xy2(_lpLine, bar_index, _lastTradedPrice)