Pine脚本现已支持成交量轨迹,让您可以直接访问每个价格K线内的详细订单流。
此次更新使您能够构建自定义轨迹指标、提取精确的成交量指标,并分析K线内交易活动,而无需依赖低时间周期的变通方法。
为什么要在Pine中使用轨迹?
通过轨迹请求,您可以立即解锁高级的K线内数据,并绘制出具有重要结构意义的订单流水平,例如:
- 精细的成交量拆分:整根K线以及特定价格水平的精确“买入”(ask)和“卖出”(bid)成交量总和
- 精确的成交量差:买卖压力之间的具体差异
- 关键竞价水平:立即访问K线的控制点 (POC)、价值区域高点 (VAH) 和价值区域低点 (VAL)
- 不平衡:特定价格行的买卖不平衡数据
通过将request.footprint()与自定义脚本结合使用,您可以以编程方式监控深度订单流数据,同时专注于策略和执行。
轨迹和数据结构的工作原理
request.footprint()函数是用于请求当前K线成交量轨迹信息的核心工具。调用该函数后,它会返回一个轨迹对象,其中包含该特定K线的所有已检索成交量轨迹数据。
数据分为两种主要结构:
- 轨迹对象:这些对象允许您访问K线的整体指标。通过使用footprint.*()函数,您可以检索诸如总买入量、总卖出量和成交量变化等数据。
- 成交量行对象:这些对象表示轨迹内的特定价格行,例如控制点 (POC) 或价值区域边界。通过使用volume_row.*()函数,您可以检索特定行的价格水平、成交量、成交量变化和不平衡情况。
注意:如果给定条形没有轨迹数据,则request.footprint()函数将返回na。
在尝试使用footprint.*()或volume_row.*()函数提取指标之前,务必确保脚本检查返回的对象为not na。
用例
下面是一个简化的脚本,演示如何请求轨迹并访问其底层数据点:
//@version=6
indicator("Footprint Data Highlight", overlay = true)
// Request the footprint object for the current bar (100 ticks per row, 70% Value Area)
footprint reqFootprint = request.footprint(100, 70)
// We use a block to ensure we only process data when the footprint is available
if not na(reqFootprint)
// 1. Access overall bar metrics from the `footprint` object
float totalBuyVol = reqFootprint.buy_volume()
float totalSellVol = reqFootprint.sell_volume()
float volumeDelta = reqFootprint.delta()
// 2. Retrieve a specific `volume_row` object (the Point of Control)
volume_row pocRow = reqFootprint.poc()
// 3. Access specific price values from the `volume_row` object
float pocUpperPrice = pocRow.up_price()
float pocLowerPrice = pocRow.down_price()
// --- USING THE VARIABLES ---
// Use Buy/Sell Volume and Delta in a label
if barstate.islast
label.new(bar_index, high,
text = "Buy: " + str.tostring(totalBuyVol, format.volume) +
"\nSell: " + str.tostring(totalSellVol, format.volume) +
"\nDelta: " + str.tostring(volumeDelta, format.volume),
color = color.new(color.blue, 20),
textcolor = color.white,
style = label.style_label_down)
// Use POC prices to highlight the POC area on the chart
linefill.new(
line.new(bar_index, pocUpperPrice, bar_index[1], pocUpperPrice, color = color.orange),
line.new(bar_index, pocLowerPrice, bar_index[1], pocLowerPrice, color = color.orange),
color.new(color.orange, 80))
// Plotting the volume delta on a separate pane (if moved to non-overlay)
// or as a reference value in the Data Window
plot(not na(reqFootprint) ? reqFootprint.total_volume() : na, "Volume Delta", display = display.data_window)
请注意,要使用这些功能,您需要拥有Premium或Ultimate方案。
要了解Pine Script®体验的最新改进,请关注用户手册的发行说明。
我们希望大家觉得这些功能和我们预想的一样实用,也请您继续向我们提供反馈和建议,以便我们不断完善平台。我们致力于为大家打造TradingView,并始终期待您的宝贵意见。
TradingView团队