如何在Pine Script中引用先前的财务值,以便我可以计算该值的增长率?

huangapple go评论59阅读模式
英文:

How do I reference a previous financial value in pinescript so that I can calculate the growth rate of that value?

问题

我试图持续计算每股收益的变化(以便稍后计算增长率)。我目前有以下代码:

eps = request.financial(syminfo.tickerid, "EARNINGS_PER_SHARE_DILUTED", "FY")

我想能够检索上一个报告期的 EARNINGS_PER_SHARE_DILUTED 值,以便计算每股收益的变化。是否有一种方法可以引用上一个报告期的值?

英文:

I am attempting to calculate the change in earnings per share on a continual basis (in order to later calculate the growth rate). I currently have:

eps = request.financial(syminfo.tickerid, "EARNINGS_PER_SHARE_DILUTED", "FY")

I would like to be able to retrieve the prior reporting period's value for EARNINGS_PER_SHARE_DILUTED so I can calculate the change in EPS. Is there a way to reference the prior reporting period's value?

答案1

得分: 1

你可以使用一个var变量来存储内存中的最新财务数据。

在下面的示例中,我使用了security()调用和barmerge.gaps_on,这样它只会在有新数据可用时更新我的变量。一旦有新数据,只需更新你的"last"和"current"变量。

//@version=5
indicator("我的脚本", overlay=true)

var float current_financial_val = na
var float last_financial_val = na

eps = request.financial(syminfo.tickerid, "EARNINGS_PER_SHARE_DILUTED", "FY")
eps_gap = request.financial(syminfo.tickerid, "EARNINGS_PER_SHARE_DILUTED", "FY", barmerge.gaps_on)

if (not na(eps_gap))    // 新财务数据
    last_financial_val := current_financial_val
    current_financial_val := eps_gap

plot(eps, color=color.white)
plot(current_financial_val, color=color.green)
plot(last_financial_val, color=color.red)

注意:你不需要eps变量。我只是将它保留在那里,这样你可以看到发生了什么。

英文:

You can use a var variable to store the last financial data in memory.

In the below example, I used the security() call with barmerge.gaps_on so that it would only update my variables once when there is new data available. Once there is new data, simply update your "last" and "current" variables.

//@version=5
indicator("My script", overlay=true)

var float current_financial_val = na
var float last_financial_val = na

eps = request.financial(syminfo.tickerid, "EARNINGS_PER_SHARE_DILUTED", "FY")
eps_gap = request.financial(syminfo.tickerid, "EARNINGS_PER_SHARE_DILUTED", "FY", barmerge.gaps_on)

if (not na(eps_gap))    // New financial data
    last_financial_val := current_financial_val
    current_financial_val := eps_gap

plot(eps, color=color.white)
plot(current_financial_val, color=color.green)
plot(last_financial_val, color=color.red)

Note: You don't need the eps variable. I just left it there so you can see what is going on.

huangapple
  • 本文由 发表于 2023年6月16日 08:00:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76486181.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定