Pine腳本現已支援成交量軌跡,讓您能直接訪問每根K線內的詳細訂單流資訊。
此更新可讓您建立自訂軌跡指標、提取精確的成交量指標,並分析盤中交易活動,而無需依賴較低時間週期的變通方法。
為什麼要在Pine腳本中使用軌跡?
軌跡請求可讓您立即解鎖高級的盤中數據,並繪製出具有重要結構意義的訂單流水平,例如:
- 細分成交量:整根K線及特定價位的精確買入(Ask)和賣出(Bid)成交量
- 精準成交量變化:買賣壓力之間的具體差值
- 關鍵拍賣價位:立即獲取K線的控制點、價值區高點和價值區低點
- 不平衡數據:特定價格行的買賣力量不平衡資訊
透過將request.footprint()與自訂腳本結合,您可以程式化監控深度訂單流數據,同時保持對交易策略與執行的專注。
軌跡與數據結構的運作方式
request.footprint()函數是用來請求目前K線成交量軌跡數據的核心工具。呼叫函數後,它會傳回一個軌跡物件,其中包含該特定K線的所有已檢索成交量軌跡數據。
數據分為兩種主要結構:
- 軌跡物件:這些物件可讓您訪問K線的整體指標。透過使用footprint.*()函數,您可以檢索諸如總買進量、總賣出量和成交量變化等數據。
- 成交量行物件:這些物件代表覆蓋範圍內的特定價格行,例如控制點或價值區域邊界。透過使用volume_row.*()函數,您可以擷取特定行的價格水準、成交量值、成交量差值和不平衡情況。
注意:如果某根K線沒有可用的軌跡數據,request.footprint()函數會回傳na。
在嘗試使用footprint.*()或volume_row.*()函數提取指標之前,請務必確保腳本檢查傳回的物件不是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團隊