去年9月,我們的一些內建Pine函數開始支援動態值作為其長度參數。現在,我們進一步擴展了此列表。現在,以下函數也可以用於動態計算的長度:
bb() bbw() cci() cmo() cog() correlation() dev() falling() mfi() percentile_linear_interpolation() percentile_nearest_rank() percentrank() rising() roc() stdev() stoch() variance() wpr()
透過傳遞序列作為長度參數,可以更輕鬆地建立自適應的Pine指標,該指標使用基於可變週期的計算。例如,以下腳本使用內建的 stdev() 函數為VWAP指標計算標準偏差範圍。每隔一個小節,stdev() 計算的長度就會增加1,直到VWAP週期重置:
//@version=4 study(title="VWAP", shorttitle="VWAP", overlay=true) src = input(title = "Source", type = input.source, defval = hlc3) t = time("D") start = na(t[1]) or t > t[1] sumSrc = src * volume sumVol = volume sumSrc := start ? sumSrc : sumSrc + sumSrc[1] sumVol := start ? sumVol : sumVol + sumVol[1] vwapValue = sumSrc / sumVol var barsSinceStart = 0 if start barsSinceStart := 0 barsSinceStart := barsSinceStart + 1 stdevLen = bar_index == 0 ? 3000 : barsSinceStart // max_bars_back workaround vwapStdev = stdev(vwapValue, stdevLen) plot(vwapValue, title="VWAP", color=color.blue) upperBand = plot(vwapValue+vwapStdev, title="Upper Band", color=color.green) lowerBand = plot(vwapValue-vwapStdev, title="Lower Band", color=color.green) upperBand2 = plot(vwapValue+vwapStdev*2, title="Upper Band 2", color=color.yellow) lowerBand2 = plot(vwapValue-vwapStdev*2, title="Lower Band 2", color=color.yellow) fill(upperBand2, lowerBand2, color=color.yellow, transp=95)
請記住,這些函數需要在每個K線上進行評估,因此應在非針對每個K線上執行的 ‘for’ 循環或 ‘if’ 塊之外使用它們。另外,將序列作為內建函數的長度傳遞有時會導致 `Pine無法確定序列的引用長度` (Pine cannot determine the referencing length of a series) 錯誤。您可以在我們的幫助中心中詳細了解它以及如何解決該錯誤。
在我們的用戶手冊的發行說明中了解有關Pine的所有更新。
我們希望大家請求的這項新功能有用。請繼續向我們發送您的反饋和建議。我們正在為您打造TradingView,很高興聽到您對我們平台更新的看法。