You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在TradingView Pine Script中实现带分钟的K线时间戳?

TradingView Pine Script 「时:分」时间戳修复方案

原代码仅提取了K线的小时信息,未获取分钟数据,因此无法生成完整的「时:分」格式时间戳。以下是修复后的代码及说明:

//@version=5
indicator("时分时间戳表格", overlay=true)

// 生成「时:分」格式时间戳,自动补零(如09:05而非9:5)
inTime = str.format("{0}:{1}", str.tostring(hour(time, syminfo.timezone), "00"), str.tostring(minute(time, syminfo.timezone), "00"))

// 创建表格
Table_Def = table.new(position = position.middle_right, columns = 30, rows = 1, frame_color = color.black, frame_width = 1, border_color = color.black, border_width = 1)

// 填充表头和时间戳
table.cell(Table_Def, column = 0, row = 0, text = "Time", text_color = color.black, text_size = size.auto, text_halign = text.align_left)
table.cell(Table_Def, column = 1, row = 0, text = inTime[29], text_color = color.black, text_size = size.auto, text_halign = text.align_right)

关键修改说明

  • 新增minute()函数提取分钟信息,配合str.tostring()的"00"参数实现数字补零,保证时间格式统一(如小时/分钟小于10时显示为两位数字)
  • 使用str.format()将小时和分钟拼接为「时:分」格式字符串,直接赋值给inTime变量
  • 移除原代码中多余的str.tostring()转换,因为inTime本身已是字符串类型

内容的提问来源于stack exchange,提问作者Vishnubhatla venkata subrahman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 13:54:55