Skip to content

request

函數

currency_rate

navi
request.currency_rate(
    from: series string,
    to: series string,
    ignore_invalid_currency: series bool = false
  ): series float

傳回當前 bar 將一單位 from 貨幣轉換為 to 貨幣的匯率。該速率由引擎的 DataProvider 提供。

參數

名稱類型預設值說明
fromseries string源貨幣代碼,例如\"USD\"currency.USD
toseries string目標貨幣代碼,例如\"EUR\"currency.EUR
ignore_invalid_currencyseries boolfalse如果是 true,則在無法確定轉換率時傳回 na,而不是引發運行時錯誤。

返回: series float


data

navi
request.data(
    function: simple string,
    args: series Map<string, any> = na,
    gaps: simple BarmergeGaps = BarmergeGaps.Off,
    lookahead: simple BarmergeLookahead = BarmergeLookahead.Off
  ): series float

呼叫引擎 DataProvider 上的自訂函式,並將回傳的時間序列對映到當前圖表 bar。args 對映僅接受 boolintfloatstring 型別的值;其他型別會導致執行時錯誤。對映中的 na 條目會被靜默忽略。無資料時回傳 na

參數

名稱類型預設值說明
functionsimple string要呼叫的 DataProvider 函式名稱。
argsseries Map<string, any>na傳遞給函式的可選 map&lt;string, any&gt; 型別參數。
gapssimple BarmergeGapsBarmergeGaps.Offbar 對映模式(參見 BarmergeGaps.Off / BarmergeGaps.On)。
lookaheadsimple BarmergeLookaheadBarmergeLookahead.Off控制前瞻語義以確保回測正確性。

返回: series float


dividends

navi
request.dividends(
    ticker: series string = syminfo.tickerid,
    field: series DividendsField = DividendsField.Gross,
    gaps: simple BarmergeGaps = BarmergeGaps.Off,
    lookahead: simple BarmergeLookahead = BarmergeLookahead.Off,
    ignore_invalid_symbol: input bool = false,
    currency: series string = syminfo.currency
  ): series float

查詢引擎的 DataProvider 以獲取當前 bar 處的股息值。支持前瞻控制。當沒有可用資料時傳回 na

參數

名稱類型預設值說明
tickerseries stringsyminfo.tickerid查詢股息的股票;默認為圖表符號。
fieldseries DividendsFieldDividendsField.Gross要檢索哪個股息數字:dividends.gross(預扣前)或 dividends.net(預扣後)。
gapssimple BarmergeGapsBarmergeGaps.Off條形映射模式(請參閲 BarmergeGaps.Off / BarmergeGaps.On)。
lookaheadsimple BarmergeLookaheadBarmergeLookahead.Off控制該值是出現在事件 bar 本身上 (lookahead_on) 還是僅在確認後出現 (lookahead_off)。
ignore_invalid_symbolinput boolfalsetrue 時,無法識別的代碼會默默產生 na
currencyseries stringsyminfo.currency用於價值轉換的貨幣代碼。

返回: series float


earnings

navi
request.earnings(
    ticker: series string = syminfo.tickerid,
    field: series EarningsField = EarningsField.Actual,
    gaps: simple BarmergeGaps = BarmergeGaps.Off,
    lookahead: simple BarmergeLookahead = BarmergeLookahead.Off,
    ignore_invalid_symbol: input bool = false,
    currency: series string = syminfo.currency
  ): series float

查詢引擎的 DataProvider 以獲取當前 bar 的收益值。支持回溯測試正確性的前瞻控制。當沒有可用資料時傳回 na

參數

名稱類型預設值說明
tickerseries stringsyminfo.tickerid查詢收益的股票;默認為圖表符號。
fieldseries EarningsFieldEarningsField.Actual要檢索哪個收入資料:earnings.actualearnings.estimateearnings.standardized
gapssimple BarmergeGapsBarmergeGaps.Off條形映射模式(請參閲 BarmergeGaps.Off / BarmergeGaps.On)。
lookaheadsimple BarmergeLookaheadBarmergeLookahead.OffBarmergeLookahead.Off(默認)時,資料點僅在後續點確認後才變得可見,從而防止回溯測試中的未來泄漏。
ignore_invalid_symbolinput boolfalsetrue 時,無法識別的代碼會默默產生 na
currencyseries stringsyminfo.currency用於價值轉換的貨幣代碼。

返回: series float


economic

navi
request.economic(
    country_code: series string,
    field: series string,
    gaps: simple BarmergeGaps = BarmergeGaps.Off,
    ignore_invalid_symbol: input bool = false
  ): series float

查詢引擎的 DataProvider 以獲取當前 bar 處的宏觀經濟指標值。當沒有可用資料時傳回 na

參數

名稱類型預設值說明
country_codeseries stringISO 3166-1 alpha-2 國家/地區代碼,例如__代碼0__,代碼1
fieldseries string要檢索的經濟指標的標識符。
gapssimple BarmergeGapsBarmergeGaps.Off條形映射模式(請參閲 BarmergeGaps.Off / BarmergeGaps.On)。
ignore_invalid_symbolinput boolfalsetrue 時,無法識別的標識符會默默地產生 na

返回: series float


financial

navi
request.financial(
    symbol: series string,
    financial_id: series string,
    period: series string,
    gaps: simple BarmergeGaps = BarmergeGaps.Off,
    ignore_invalid_symbol: input bool = false,
    currency: series string = syminfo.currency
  ): series float

查詢引擎的 DataProvider 以獲取當前 bar 處的財務指標值。提供程序流式傳輸帶有時間戳的資料點,VM 使用 gaps 模式將這些資料點映射到圖表 bars 上。當沒有可用資料時傳回 na

參數

名稱類型預設值說明
symbolseries string要查詢其財務狀況的符號。
financial_idseries string要檢索的財務指標的標識符。
periodseries string報告期:\"FQ(季度)或FY\"(年度)。
gapssimple BarmergeGapsBarmergeGaps.Off當資料點與圖表 bar 不對齊時控制 bar 映射。 BarmergeGaps.Off 前向填充; BarmergeGaps.On 留下間隙作為 na
ignore_invalid_symbolinput boolfalsetrue 時,無法識別的符號會默默地產生 na
currencyseries stringsyminfo.currency用於價值轉換的貨幣代碼;默認為圖表符號的貨幣。

返回: series float


security

navi
request.security(
    symbol: series string,
    timeframe: series string,
    expression: instructions<T>,
    gaps: simple BarmergeGaps = BarmergeGaps.Off,
    lookahead: simple BarmergeLookahead = BarmergeLookahead.Off,
    ignore_invalid_symbol: input bool = false,
    currency: series string = na,
    calc_bars_count: simple int = na
  ): series T

評估另一個交易品種或時間範圍上的 expression 並將結果映射到當前圖表上。

參數

名稱類型預設值說明
symbolseries string請求的符號。
timeframeseries string請求的時間範圍字符串,例如 \"D60W\"
expressioninstructions<T>要在請求的上下文中執行的表達式。
gapssimple BarmergeGapsBarmergeGaps.Off如何將缺失的請求 bars 映射回當前圖表。
lookaheadsimple BarmergeLookaheadBarmergeLookahead.Off請求的值是否可以展望歷史 bars。
ignore_invalid_symbolinput boolfalse如果 true,則對於未知符號傳回 na,而不是引發錯誤。
currencyseries stringna用於價格轉換的可選貨幣。
calc_bars_countsimple intna為請求流加載的最近歷史記錄窗口的可選正限制。

返回: series T

示例

navi
// Get daily close of a different symbol on the current intraday chart let
dailyClose = request.security("AAPL", "D", close);
plot(dailyClose, title: "AAPL Daily Close");
navi
// Request daily high and low simultaneously using a tuple expression let
(dHigh, dLow) = request.security("AAPL", "D", (high, low));
plot(dHigh, title: "Daily High", color: color.GREEN);
plot(dLow,  title: "Daily Low",  color: color.RED);

security_lower_tf

navi
request.security_lower_tf(
    symbol: series string,
    timeframe: series string,
    expression: instructions<T>,
    ignore_invalid_symbol: input bool = false,
    currency: series string = na,
    ignore_invalid_timeframe: input bool = false,
    calc_bars_count: simple int = na
  ): series Array<T>

在較低時間範圍內評估 expression 併為當前圖表 bar 內的每個較低時間範圍 bar 傳回一個陣列元素。

參數

名稱類型預設值說明
symbolseries string請求的符號。
timeframeseries string較低或等於時間範圍字符串,例如 \"15\"
expressioninstructions<T>針對每個較低時間範圍 bar 計算的表達式。
ignore_invalid_symbolinput boolfalse如果 true,則對於未知符號傳回 na,而不是引發錯誤。
currencyseries stringna用於價格轉換的可選貨幣。
ignore_invalid_timeframeinput boolfalse如果為 true,則當請求的時間範圍不低於圖表時間範圍時傳回 na
calc_bars_countsimple intna為請求流加載的最近歷史記錄窗口的可選正限制。

返回: series Array<T>


splits

navi
request.splits(
    ticker: series string = syminfo.tickerid,
    field: series SplitsField = SplitsField.Denominator,
    gaps: simple BarmergeGaps = BarmergeGaps.Off,
    lookahead: simple BarmergeLookahead = BarmergeLookahead.Off,
    ignore_invalid_symbol: input bool = false
  ): series float

查詢引擎的 DataProvider 以獲取當前 bar 處的股票分割值。支持前瞻控制。當沒有可用資料時傳回 na

參數

名稱類型預設值說明
tickerseries stringsyminfo.tickerid要查詢其拆分的股票代碼;默認為圖表符號。
fieldseries SplitsFieldSplitsField.Denominator要檢索分流比的哪個組成部分:splits.numeratorsplits.denominator
gapssimple BarmergeGapsBarmergeGaps.Off條形映射模式(請參閲 BarmergeGaps.Off / BarmergeGaps.On)。
lookaheadsimple BarmergeLookaheadBarmergeLookahead.Off控制該值是出現在事件 bar 本身上 (lookahead_on) 還是僅在確認後出現 (lookahead_off)。
ignore_invalid_symbolinput boolfalsetrue 時,無法識別的代碼會默默產生 na

返回: series float

基於 MIT 許可證發佈。