首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Thinkscript获取收入总数?

如何使用Thinkscript获取收入总数?
EN

Stack Overflow用户
提问于 2017-09-26 19:38:12
回答 2查看 330关注 0票数 0

我想数一下图表上的收入总数。如果这是一年的日线图,我应该会得到4个收益。没有错误消息,但标签未显示在图表上。

代码语言:javascript
复制
def earningCount = if IsNaN(earningCount) then 0 else if hasEarnings() then earningCount + 1 else earningCount;
AddLabel(yes, "There are total " + earningCount + " earnings"); 
EN

回答 2

Stack Overflow用户

发布于 2018-01-03 11:30:40

您需要做的是从第一天开始,然后遍历前一天的hasEarnings()。不幸的是,在thinkscript中没有任何for/while循环功能,这将是非常乏味的:

代码语言:javascript
复制
def earningCount;

#get latest date
def today = getYYYYMmDd();

#get first date in chart
def firstDay = first(today);

#get number of days to iterate through:
def numOfDays = CountTradingDays(firstDay,today);

#Ask for each day one at a time: if hasEarnings() then earningCount + 1 else Double.NaN;

#today
today

#day before
today[1]

#day before that... etc..
today[2]

#... until first day in chart
today[numOfDays]

这不是你想要的最佳解决方案。或者,你可以问图表中有多少年,乘以4,因为你知道通常有4年的收入/年……

票数 0
EN

Stack Overflow用户

发布于 2018-08-11 23:18:01

代码语言:javascript
复制
def earningCount = if IsNaN(earningCount[1]) then 0 else if hasEarnings() then earningCount[1] + 1 else earningCount[1];
AddLabel(yes, "There are total " + earningCount + " earnings"); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46425497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档