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

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

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

I wanted to program algorithm using a trend line. It might not as simple as just crossover moving average, but as an example:

you can code crossover a SMA line like this:

crossover(close, sma(close, 50)) 

but how can I code crossover a trend line?

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

.. and more tricky algorithm using the trend line instance 

Is this not possible, or do you have an idea? Thanks.

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

Are you using line.new function to define the lineInstance variable? If yes, you can use line.get_price(id, x) function to get the current y-value of the line object, and then pass it to crossover function.

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