从今天起,我无法在松树脚本中得到回溯。我已经将函数定义为减去当前时间的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)任何帮助都将不胜感激。
发布于 2019-03-07 15:02:42
好像是松树的不一致。如果准确性不那么重要,我建议在时间戳中使用自写函数:
//@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
我并不完全理解你的代码的逻辑,因为你要减去两个日期,然后把这个差异转换成一个新的日期。对我来说没有意义。但是也许这只是堆栈溢出的一个例子,所以没关系
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天前放一条线(如果当天没有任何条子,则什么也不放),并且必须在日期或离今天更近的地方放一条线。
发布于 2019-09-20 23:19:15
round函数将其转换为整数?[0]后的yr等。https://stackoverflow.com/questions/55036549
复制相似问题