英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论