pine-script - UNIX 中每个烛台的持续时间
问题描述
我们如何计算 UNIX 中每个蜡烛(不是 Session)的持续时间?例如,每日时间范围为 86400000。
我使用了以下代码,它适用于每周 7 天、每天 24 小时活跃的加密货币市场,但在股票市场中它返回会话时间:
interval := na(interval) ? time_close - time : interval
解决方案
您不需要在每个柱上都进行计算。你可以用这个:
var int interval = time_close - time
它适用于加密市场和股票市场,并返回当前时间范围内柱的持续时间(以毫秒为单位)。
编辑 1
我认为这会更好
var float interval = na
if bar_index == 1
interval := time - time[1]
编辑 2
//@version=4
study("Time Offset Calculation Framework - PineCoders FAQ", "", true, max_lines_count = 10)
// ———————————————————— Functions.
// ————— Converts current chart resolution into a float minutes value.
f_resInMinutes() =>
_resInMinutes = timeframe.multiplier * (
timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. :
timeframe.isdaily ? 60. * 24 :
timeframe.isweekly ? 60. * 24 * 7 :
timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
var float resInMinutes = f_resInMinutes()
var float resInSeconds = resInMinutes * 60
var float resInMilliSeconds = resInSeconds * 1000
// Plot chart interval in minutes in Data Window.
plotchar(resInMinutes, "resInMinutes", "", location.top, size = size.tiny)
plotchar(resInSeconds, "resInSeconds", "", location.top, size = size.tiny)
plotchar(resInMilliSeconds, "resInMilliSeconds", "", location.top, size = size.tiny)
推荐阅读
- logging - Serilog ReadFrom 配置
- ios - 在 ViewController 上设置默认的后退按钮
- json - 在 Swift 中默认使类符合 Codable
- c# - 如何在 ASP.NET Core Razor 页面中使用查询构建 @Url.Page 链接
- django - Django 如何使用表单按钮传递 url 参数?
- javascript - 使用 forEach 迭代 NodeList 时,如何使用仅绑定而不是调用?
- javascript - 进入/退出未正确清理强制布局中弹出的节点/链接
- java - JVM 堆外内存地址会发生变化吗?
- ios - 为什么在 UIImagePNGRepresentation 之后图像大小会增加?
- javascript - 当对象已更新时,React 访问对象的属性会返回旧数据