我今天无法从松树脚本中获得回溯。我已经定义了从当前时间减去UNIX时间戳的函数。但是下面的代码导致"Timestamp requires integer parameter than series parameter"
错误
getdate() =>
tt = timenow - 1549238400
yr = year(tt)
mt = month(tt)
dt = dayofmonth(tt)
timestamp(yr[0], mt[0], dt[0], 0 ,0)
任何帮助将不胜感激。
似乎是松树的不一致。如果准确性不是那么重要,我建议使用自写功能进行时间戳:
//@version=3
study("Timestamp")
MILLISECONDS_IN_DAY = 86400000
TIMESTAMP_BEGIN_YEAR = 1970
myTimestamp(y, m, d) =>
years = y - TIMESTAMP_BEGIN_YEAR
years * MILLISECONDS_IN_DAY * 365.25 + (m - 1) * 30 * MILLISECONDS_IN_DAY + (d - 1) * MILLISECONDS_IN_DAY
// TEST:
tmspm = myTimestamp(2019, 3, 5)
y = year(tmspm)
m = month(tmspm)
d = dayofmonth(tmspm)
plot(y, color=green)
plot(m, color=red)
plot(d, color=maroon)
顺便说一下,timenow
以千分之一秒的形式返回一个值,而你试图用秒来减去它:1549238400
我并不完全理解您的代码的逻辑,因为您减去了两个日期,然后将该差异转换为新的日期。对我来说,没有任何意义。但也许它只是stackoverflow的一个例子,所以没关系
UPD:你的代码不起作用,因为你减去时间1549238400,但29天前毫秒是2505600000.我希望下一个代码有用:
//@version=3
study("My Script")
_MILLISECONDS_IN_DAY = 86400000
_29_DAYS_MILLIS = 29 * _MILLISECONDS_IN_DAY
reqDate = timenow - _29_DAYS_MILLIS
reqYear = year(reqDate)
reqMonth = month(reqDate)
reqDay = dayofmonth(reqDate)
linePlotted = false
linePlotted := nz(linePlotted[1], false)
vertLine = na
col = color(red, 100)
//this puts a line exactlty 29 day ago or nothing if there wasn't a trading day at the date. If you want to put a line 29 days ago or closer, then:
// if year >= reqYear and month >= reqMonth and dayofmonth >= reqDay and not linePlotted
if year == reqYear and month == reqMonth and dayofmonth == reqDay and not linePlotted
linePlotted := true
vertLine := 1000
col := color(red, 0)
plot(vertLine, style=histogram, color=col)
注意,有两种可能的条件取决于你需要的东西:29天前准确地放一条线(如果当天没有任何条形线,则放一条线)并且必须在日期或更接近今天放置一条线