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).
Release Note
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.
ไลบรารีไพน์
ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนได้เผยแพร่ Pine code นี้เป็นโอเพนซอร์สไลบรารีเพื่อให้ Pine โปรแกรมเมอร์คนอื่นในชุมชนของเราสามารถนำไปใช้ซ้ำได้ ต้องขอบคุณผู้เขียน! คุณสามารถใช้ไลบรารีนี้ในแบบส่วนตัวหรือในการเผยแพร่แบบโอเพนซอร์สอื่น ๆ แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
ไลบรารีไพน์
ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนได้เผยแพร่ Pine code นี้เป็นโอเพนซอร์สไลบรารีเพื่อให้ Pine โปรแกรมเมอร์คนอื่นในชุมชนของเราสามารถนำไปใช้ซ้ำได้ ต้องขอบคุณผู้เขียน! คุณสามารถใช้ไลบรารีนี้ในแบบส่วนตัวหรือในการเผยแพร่แบบโอเพนซอร์สอื่น ๆ แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน