像在 PIne Script TradingView 中使用 SMA 一样获取趋势线的价值?

Get value of Trend line like you do with SMA in PIne Script TradingView?

我想使用趋势线编写算法。它可能不像交叉移动平均线那么简单,但举个例子:

您可以像这样对 SMA 线进行编码:

crossover(close, sma(close, 50)) 

但是我如何编写交叉趋势线的代码?

lineInstance = .. // define a trend line 
crossover(close, lineInstance)
crossover(close[1], lineInstance[1])

.. and more tricky algorithm using the trend line instance 

这不可能吗,或者你有什么想法?谢谢

您是否使用 line.new 函数来定义 lineInstance 变量? 如果是,则可以使用line.get_price(id, x)函数获取线对象的当前y值,然后将其传递给crossover函数。

currentLineValue = line.get_price(lineInstance, 0)
priceCrossUpLine = crossover(close, currentLineValue)