pine-script - 我们可以强制一个函数重绘吗?
问题描述
我创建了这个函数来获取给定柱偏移的时间戳。
// on the 1mn timeframe
getBarTime(lookbehind) =>
timestamp(year(timenow), month(timenow), dayofmonth(timenow), hour(timenow), minute(timenow), 0) - lookbehind*60*1000
它似乎按预期工作,但是当我绘制时它似乎没有重新绘制:
plot(time == getBarTime(2) ? 1 : 0)
它冻结输出时间戳并且从不重绘。
解决方案
您可以使用 获取任何给定偏移量的开放时间time[offset]
。
这允许查看实时栏中发生的情况:
//@version=4
study("")
// on the 1mn timeframe
getBarTime(lookbehind) =>
timestamp(year(timenow), month(timenow), dayofmonth(timenow), hour(timenow), minute(timenow), 0) - lookbehind*60*1000
// Condition is only true once, when the script executes on the second to last bar of the dataset.
bgcolor(time == getBarTime(2) ? color.green : na)
plot(getBarTime(2))
// Get time 2 bars back.
plotchar(time[2], "time[2]", "", location.top, size = size.tiny)
// See `timenow` advance on each realtime bar iteration (has a 1sec precision).
plotchar(timenow, "timenow", "", location.top, size = size.tiny)
在历史柱上,timenow
将每秒更新一次,因此只有当您的脚本在它们上执行超过 1 秒时才会看到更改。
推荐阅读
- docker - 自动构建 docker 容器(java 后端,角度前端)
- c - 带参数的读取和系统调用的含义
- json - 在 Azure LogicApps 中解析 JSON
- r - 使用数据框中的名称更改字段名称
- php - 结束进程由 PHP exec 在 Ubuntu 中使用 Apache 创建
- python - 如何在python中修复'TypeError:'NoneType'类型的参数不可迭代'
- amazon-web-services - 如何在 AWS 上为 Elasticsearch 服务添加协调节点?
- python - 是否可以将 CSV 上传到 redshift 并让它自动运行并导出保存的查询?
- mysql - sql IN 关键字和多个输入列 - 如何组合成单个列
- java - 为什么 Mockito 会抛出 NPE(带有弹簧靴的junit5)?