tradingview api - Price Earnings (PE) Spread between two stocks script - Stack Overflow

I am new to Pinescript and tried writing the below code but come up with the following error. It is act

I am new to Pinescript and tried writing the below code but come up with the following error. It is actually I believe a simple script as I just want to visually see a chart showing me the historical PE spread between two listed stocks.

e.g. stock A P/E ratio = 18, stock B P/E ratio = 13. Show me the historical and current PE spread between the two numbers, i.e. Stock A P/E ratio (18) - stock B P/E ratio (13) = +5.

From a chart perspective this would be a line and the horizon would be 0 (both PE's the same) and positive 5 would be above the line and indicate Stock A therefore has a higher PE than stock B currently.
I found the following code on google and then I replicated this inside Trading View and had the noted error.

Appreciate any assistance.

//@version=6
indicator("P/E Spread", shorttitle="P/E Spread", overlay=true)

// Get P/E ratios for both stocks
stock1_pe = ta.pe(ticker1)
stock2_pe = ta.pe(ticker2)

// Calculate the spread
pe_spread = stock1_pe - stock2_pe

// Plot the spread
plot(pe_spread, color=color.blue, title="P/E Spread")

My script:

//@version=6
indicator(title = "P/E Spread", shorttitle="P/E Spread", overlay=true)

// Get P/E ratios for both stocks
stock1_pe = "ASX:WOW"
stock2_pe = "ASX:COL"

// Calculate the spread
pe_spread = stock1_pe - stock2_pe

// Plot the spread
plot(pe_spread, color=color.blue, title="P/E Spread")

and now I get the following error:

"Cannot call "operator -" with argument "expr0"="stock1_pe". An argument of "const string" type was used but a "const int" is expected."

So I think I need to retrieve the PE ratio for the stock code from a table(?) in the line "Get P/E ratios for both stocks...correct? however what is the correct format?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744298578a4567385.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信