我想数一下图表上的收入总数。如果这是一年的日线图,我应该会得到4个收益。没有错误消息,但标签未显示在图表上。
def earningCount = if IsNaN(earningCount) then 0 else if hasEarnings() then earningCount + 1 else earningCount;
AddLabel(yes, "There are total " + earningCount + " earnings"); 发布于 2018-01-03 11:30:40
您需要做的是从第一天开始,然后遍历前一天的hasEarnings()。不幸的是,在thinkscript中没有任何for/while循环功能,这将是非常乏味的:
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年的收入/年……
发布于 2018-08-11 23:18:01
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"); https://stackoverflow.com/questions/46425497
复制相似问题