兩個新的Pine Script™函數request.security_lower_tf()和request.economic(),以及對現有request.security()函數的改進,允許您的腳本訪問更多數據。
request.security_lower_tf()
新的request.security_lower_tf()函數使圖表可用更短的時間週期來請求數據,變得更加容易。在這個新函數之前,訪問60分鐘圖表K線的所有1分鐘intrabars需要複雜的使用者定義函數和request.security()呼叫。新的request.security_lower_tf()透過回傳包含每個intrabar所提供表達式的一個數組值來使它變得輕而易舉。請注意,每個圖表K線的intrabar可能會有所不同。
以下指標著眼於每個圖表K線擴張中1分鐘intrabar的方向。如果大多數intrabar與圖表K線的極性不同,我們將其主體著色為橙色。

//@version=5
indicator("Polarity Divergences", overlay = true)
// Fetch an array containing the +1/0/-1 direction of each 1min intrabar.
array<float> directionsArray = request.security_lower_tf(syminfo.tickerid, "1", math.sign(close - open))
// Color the chart bar orange when the majority of
// intrabar directions does not match the chart bar's direction.
barcolor(math.sign(array.sum(directionsArray)) != math.sign(close - open) ? color.orange : na)
// Plot the number of intrabars in indicator values and the Data Window.
plotchar(array.size(directionsArray), "Intrabars", "", location.top)
request.economic()
用request.economic()函數來取得一個國家或地區的經濟數據。經濟數據包括國家經濟狀況(GDP、通貨膨脹率等)或特定行業(鋼鐵生產、ICU病床等)的資訊:
//@version=5
indicator("Gross domestic product of the US")
plot(request.economic("US", "GDP"))
我們的幫助中心文章列出了所有可用的國家/地區和可用的指標。每個指標的附加幫助中心文章對其進行了描述,並列出了可用的國家/地區。這是GDP的幫助中心文章。
request.security()的改進
request.security()現在可以回傳這些類型的陣列、字符串、布林值、顏色和元組:
//@version=5
indicator("")
// Create an array containing OHLC values.
array<float> ohlc = array.from(open, high, low, close)
// Request a tuple evaluated in the context of the "NASDAQ:TSLA" symbol at the chart's timeframe.
// The tuple contains:
// - The array of OHLC values.
// - A string representation of the OHLC values using the symbol's tick precision.
// - The currency string of the symbol.
[ohlcArray, ohlcString, curString] = request.security("NASDAQ:TSLA", timeframe.period, [ohlc, str.tostring(ohlc, format.mintick), syminfo.currency])
if barstate.islastconfirmedhistory
label.new(bar_index, high,
"OHLC values: " + str.tostring(ohlcArray) +
"\nFormatted OHLC values: " + ohlcString +
"\nCurrency: " + curString)
要隨時了解Pine的新功能,請密切關注用戶手冊的發行說明。PineCoders帳戶還可以從Telegram Squawk Box頻道、Twitter帳戶以及TradingView上的”Pine Script™ Q&A”公共聊天室的廣播中更新。
我們希望您可以發現這些很實用的改進。請繼續向我們發送您的反饋。我們為用戶建構TradingView,我們很高興收到您的來信。