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

如何在TradingView的Pine Editor中绘制自定义买卖数据点箭头

在TradingView Pine Editor中展示自定义成交数据点(绿色箭头)的方法

可行,有两种实用方案可以实现:

方案一:硬编码数据(适合小数据集)

如果你的成交数据量不大,直接把Python生成的数组转换成Pine Script可识别的格式,用plotshape绘制绿色箭头即可:

//@version=5
indicator("自定义买入信号", overlay=true)

// 直接写入Python生成的时间戳(epoch秒)和成交价格
var int[] buy_timestamps = array.new_int(3, 1626377856, 1626394565, 1626575616)
var float[] buy_prices = array.new_float(3, 31004.32, 33041.95, 32218.59)

// 遍历数据,匹配K线时间并绘制箭头
for i = 0 to array.size(buy_timestamps) - 1
    target_ts = array.get(buy_timestamps, i)
    target_price = array.get(buy_prices, i)
    // 判断成交时间落在当前K线范围内
    if time >= target_ts and time[1] < target_ts
        plotshape(series=target_price, title="买入箭头", location=location.belowbar, 
                  color=color.green, style=shape.arrowup, size=size.small)

方案二:CSV导入(适合大数据量)

如果数据较多,建议把Python生成的数据导出为CSV,再导入TradingView后调用:

  1. Python导出CSV:把数据保存为如下格式的CSV文件(第一列是epoch秒级时间戳,第二列是价格):
timestamp,price
1626377856,31004.32
1626394565,33041.95
1626575616,32218.59
  1. TradingView导入CSV:点击「添加指标」→「导入」→「上传CSV文件」,选择你的CSV,设置时间列为timestamp,价格列为price,完成导入后记录数据集的名称(比如MY_BUY_ORDERS)。

  2. Pine Script调用并绘制箭头:

//@version=5
indicator("自定义买入信号", overlay=true)

// 调用导入的自定义数据集
custom_buy_data = request.security("MY_BUY_ORDERS", timeframe.period, close)

// 当数据存在时绘制绿色箭头
plotshape(series=not na(custom_buy_data), title="买入箭头", location=location.belowbar, 
          color=color.green, style=shape.arrowup, size=size.small)

注意事项

  • 确保时间戳是秒级Unix时间戳,TradingView的time变量默认用秒级,若Python生成的是毫秒级需除以1000转换。
  • 可根据需求调整plotshape的style参数,比如用shape.labelup替代shape.arrowup,还能添加文字标签。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 20:20:04