Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...