0

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

def earningCount = if IsNaN(earningCount) then 0 else if hasEarnings() then earningCount + 1 else earningCount;
AddLabel(yes, "There are total " + earningCount + " earnings"); 
4

2 回答 2

0

您需要做的是从第一天开始,然后遍历前一天询问 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-01-03T03:30:40.480 回答
0
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"); 
于 2018-08-11T15:18:00.667 回答