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

如何在TradingView PineJS中设置标记的abovebar、belowbar位置?

问题

基于TradingView Charting Library(PineJS)开发自定义指标时,使用getTimescaleMarks方法创建的标记默认显示在对应日期的图表最底部,想将标记位置设置为abovebar、belowbar等,该如何实现?

代码示例:

getTimescaleMarks: (symbolInfo,startDate,endDate,onDataCallback,resolution) => {
    var arr = [
            {
                
                id: "marker-1",
                time: 1683158400000 / 1000, // timestamp in seconds
                // position: "aboveBar",
                color: "green",
                // shape: "circle",
                text: "My Marker",
                label: "B",
                labelFontColor: "white",
                minSize: 20
        },
    ]
    onDataCallback(arr);
    console.log("-----running");
    }
解决方案

首先要明确:getTimescaleMarks是专门用于生成时间轴(底部)标记的API,它的设计就是固定显示在图表底部的时间轴区域,并不支持abovebar、belowbar这类和K线相关的位置设置。

如果想要在K线的上方或下方显示标记,你需要换用Pine Script中的plotshape函数,或者在自定义指标的逻辑里使用与K线价格关联的标记生成方式,而不是getTimescaleMarks。

举个Pine Script的简单示例,实现K线上方的标记:

//@version=5
indicator("My Custom Marker", overlay=true)
// 指定时间点(对应你代码中的1683158400000毫秒,即2023-05-04 00:00:00 UTC)
targetTime = timestamp(2023, 5, 4, 0, 0)
// 当当前K线时间匹配时,在K线上方绘制标记
if time == targetTime
    plotshape(series=high, title="Buy Marker", location=location.abovebar, color=color.green, style=shape.labelup, text="B", textcolor=color.white)

如果你是在Charting Library的JavaScript环境中通过自定义指标扩展,也需要在Pine脚本层面实现位置控制,而不是通过getTimescaleMarksAPI。

内容的提问来源于stack exchange,提问作者torq1284

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 23:03:32