PINE LIBRARY
업데이트됨 ContractResolver

Library "ContractResolver"
Classify a TradingView symbol (stock / crypto / future / etc.) and, for
continuous futures, resolve the real front-month contract ticker with a
4-digit year (e.g. "MNQ1!" -> "MNQU2026"). Prefers the built-in
syminfo.current_contract (authoritative, roll-aware) and falls back to a
calendar estimate only when current_contract is na.
monthCode(m)
Month number (1-12) -> futures month-code letter. Returns na if out of range.
Parameters:
m (int): Month number, 1-12.
Returns: Single-letter month code, or na.
monthNumber(code)
Month-code letter -> month number (1-12). Returns na if not a valid code.
Parameters:
code (string): Single-letter month code (case-insensitive).
Returns: Month number 1-12, or na.
resolve(ticker, exchange, symType, currentContract, refTime, rollDay)
Resolve a symbol into its asset class and, for continuous futures, the
front-month contract ticker. Pass syminfo.current_contract for an exact,
roll-aware result; if it is na, a calendar estimate is used (approximated=true).
Parameters:
ticker (string): Symbol without exchange prefix (e.g. syminfo.ticker).
exchange (string): Exchange / prefix (e.g. syminfo.prefix).
symType (string): syminfo.type ("stock","crypto","futures","forex","fund","index","dr"...).
currentContract (string): syminfo.current_contract (na when chart is not a continuous future).
refTime (int): Reference time (ms) for the estimate fallback; 0 -> use timenow.
rollDay (int): Day-of-month threshold for rolling to the next contract in the fallback.
Returns: A Contract object.
resolveChart(rollDay)
Convenience wrapper: resolve the chart's own symbol from its syminfo.* fields.
Parameters:
rollDay (int): Day-of-month threshold used only by the estimate fallback.
Returns: A Contract object for the current chart symbol.
format(c, pattern)
Build a custom string from a resolved Contract using a placeholder pattern.
Placeholders: {root} {mc} {m} {mm} {yyyy} {yy} {ticker} {exch} {class}
e.g. format(c, "{exch}:{root}{mc}{yyyy}") -> "CME_MINI:MNQU2026"
Parameters:
c (Contract): A Contract (typically from resolve / resolveChart).
pattern (string): Template string containing any of the placeholders above.
Returns: The pattern with placeholders substituted (missing fields -> "").
Contract
Parsed/resolved symbol.
Fields:
ticker (series string): Original ticker without exchange prefix (e.g. "MNQ1!").
exchange (series string): Exchange / prefix (e.g. "CME_MINI").
assetClass (series string): "stock" | "crypto" | "future" | "forex" | "index" | "fund" | "other".
isContinuous (series bool): True when the ticker is a continuous future (ends with "!").
root (series string): Futures root (e.g. "MNQ"); na for non-futures.
monthCode (series string): Futures month letter (F,G,H,J,K,M,N,Q,U,V,X,Z); na for non-futures.
contractMonth (series int): Contract month 1-12; na for non-futures.
contractYear (series int): 4-digit contract year; na for non-futures.
resolved (series string): Final ticker: real contract for futures, unchanged for stock/crypto/other.
approximated (series bool): True when month/year were estimated by calendar (not from current_contract).
Classify a TradingView symbol (stock / crypto / future / etc.) and, for
continuous futures, resolve the real front-month contract ticker with a
4-digit year (e.g. "MNQ1!" -> "MNQU2026"). Prefers the built-in
syminfo.current_contract (authoritative, roll-aware) and falls back to a
calendar estimate only when current_contract is na.
monthCode(m)
Month number (1-12) -> futures month-code letter. Returns na if out of range.
Parameters:
m (int): Month number, 1-12.
Returns: Single-letter month code, or na.
monthNumber(code)
Month-code letter -> month number (1-12). Returns na if not a valid code.
Parameters:
code (string): Single-letter month code (case-insensitive).
Returns: Month number 1-12, or na.
resolve(ticker, exchange, symType, currentContract, refTime, rollDay)
Resolve a symbol into its asset class and, for continuous futures, the
front-month contract ticker. Pass syminfo.current_contract for an exact,
roll-aware result; if it is na, a calendar estimate is used (approximated=true).
Parameters:
ticker (string): Symbol without exchange prefix (e.g. syminfo.ticker).
exchange (string): Exchange / prefix (e.g. syminfo.prefix).
symType (string): syminfo.type ("stock","crypto","futures","forex","fund","index","dr"...).
currentContract (string): syminfo.current_contract (na when chart is not a continuous future).
refTime (int): Reference time (ms) for the estimate fallback; 0 -> use timenow.
rollDay (int): Day-of-month threshold for rolling to the next contract in the fallback.
Returns: A Contract object.
resolveChart(rollDay)
Convenience wrapper: resolve the chart's own symbol from its syminfo.* fields.
Parameters:
rollDay (int): Day-of-month threshold used only by the estimate fallback.
Returns: A Contract object for the current chart symbol.
format(c, pattern)
Build a custom string from a resolved Contract using a placeholder pattern.
Placeholders: {root} {mc} {m} {mm} {yyyy} {yy} {ticker} {exch} {class}
e.g. format(c, "{exch}:{root}{mc}{yyyy}") -> "CME_MINI:MNQU2026"
Parameters:
c (Contract): A Contract (typically from resolve / resolveChart).
pattern (string): Template string containing any of the placeholders above.
Returns: The pattern with placeholders substituted (missing fields -> "").
Contract
Parsed/resolved symbol.
Fields:
ticker (series string): Original ticker without exchange prefix (e.g. "MNQ1!").
exchange (series string): Exchange / prefix (e.g. "CME_MINI").
assetClass (series string): "stock" | "crypto" | "future" | "forex" | "index" | "fund" | "other".
isContinuous (series bool): True when the ticker is a continuous future (ends with "!").
root (series string): Futures root (e.g. "MNQ"); na for non-futures.
monthCode (series string): Futures month letter (F,G,H,J,K,M,N,Q,U,V,X,Z); na for non-futures.
contractMonth (series int): Contract month 1-12; na for non-futures.
contractYear (series int): 4-digit contract year; na for non-futures.
resolved (series string): Final ticker: real contract for futures, unchanged for stock/crypto/other.
approximated (series bool): True when month/year were estimated by calendar (not from current_contract).
릴리즈 노트
v2 Added ability to use previous contractsUpdated:
resolve(ticker, exchange, symType, currentContract, refTime, rollDay, previous)
Resolve a symbol into its asset class and, for continuous futures, the
front-month contract ticker. Pass syminfo.current_contract for an exact,
roll-aware result; if it is na, a calendar estimate is used (approximated=true).
Parameters:
ticker (string): Symbol without exchange prefix (e.g. syminfo.ticker).
exchange (string): Exchange / prefix (e.g. syminfo.prefix).
symType (string): syminfo.type ("stock","crypto","futures","forex","fund","index","dr"...).
currentContract (string): syminfo.current_contract (na when chart is not a continuous future).
refTime (int): Reference time (ms) for the estimate fallback; 0 -> use timenow.
rollDay (int): Day-of-month threshold for rolling to the next contract in the fallback.
previous (bool): When true, return the previous contract (one step back in the cycle) instead of the front month.
Returns: A Contract object.
resolveChart(rollDay, previous)
Convenience wrapper: resolve the chart's own symbol from its syminfo.* fields.
Parameters:
rollDay (int): Day-of-month threshold used only by the estimate fallback.
previous (bool): When true, return the previous contract instead of the front month.
Returns: A Contract object for the current chart symbol.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.