Warm tip: This article is reproduced from serverfault.com, please click

algorithmic trading-是否像在PIne Script TradingView中使用SMA一样获得趋势线的价值?

(algorithmic trading - Get value of Trend line like you do with SMA in PIne Script TradingView?)

发布于 2020-12-30 12:01:51

我想使用趋势线对算法进行编程。它可能不像交叉移动平均线那么简单,但作为一个例子:

你可以像这样对 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 

这是不可能的,或者你有什么想法?谢谢。

Questioner
pupsozeyde
Viewed
0
e2e4 2020-12-30 21:26:21

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

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