最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin5浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论