Mis à jour

fsl_futures

931
Library "fsl_futures"
Futures helpers for TradingView.
Provides month code constants and utilities for determining allowed / major
contract months per futures root (e.g., SI uses HKNUZ).

allMonthCodes()
  Returns the standard CME-style futures month codes as an array.
  Returns: array<string> of month codes in order: F,G,H,J,K,M,N,Q,U,V,X,Z

allMonthCodesStr()
  Returns all month codes as a single string for quick membership checks.
  Returns: string "FGHJKMNQUVXZ"

majorMonthsByRoot(product_root)
  Returns the major month-code subset for a given futures root.
If the root is not mapped, defaults to all months.
  Parameters:
    product_root (string): Futures root symbol, e.g. "SI", "ES", "CL"
  Returns: string of allowed month codes (e.g., "HKNUZ" for SI), otherwise "FGHJKMNQUVXZ"

allowedMonthsByRoot(product_root)
  Returns the allowed month-code subset for a given futures root.
If the root is not mapped, defaults to all months.
  Parameters:
    product_root (string): Futures root symbol, e.g. "SI", "ES", "CL"
  Returns: string of allowed month codes (e.g., "HKNUZ" for SI), otherwise "FGHJKMNQUVXZ"

isMajorMonth(product_root, month_code)
  Checks whether a month code is major for a given futures root.
  Parameters:
    product_root (string): Futures root symbol, e.g. "SI"
    month_code (string): Single-letter month code, e.g. "H"
  Returns: bool true if month_code is included in the major set for that root

isAllowedMonth(product_root, month_code)
  Checks whether a month code is allowed for a given futures root.
  Parameters:
    product_root (string): Futures root symbol, e.g. "SI"
    month_code (string): Single-letter month code, e.g. "H"
  Returns: bool true if month_code is included in the allowed set for that root
Notes de version
v2

Added:
get_forward_curve_symbols(exchange, product_root, future_numbers, allowed_months)
  Generates a sequence of forward futures contract symbols starting from the
current calendar month and progressing forward until the requested number
of contracts is collected. Only contracts whose month codes are present in
the allowed month set are included.

The function advances month-by-month and automatically rolls the year when
moving past December. If an exchange prefix is provided, it is prepended
to each generated symbol.
  Parameters:
    exchange (string): Exchange prefix used for symbol construction
(e.g., "COMEX", "CME"). Use "" for no prefix.
    product_root (string): Futures root symbol (e.g., "SI", "CL", "ES").
    future_numbers (int): Number of forward contracts to generate.
    allowed_months (string): String containing allowed futures month codes
(e.g., "HMUZ" for quarterly contracts).
  Returns: array<string> Array of forward contract symbols ordered by maturity.
Notes de version
v3

Added:
CurvePoint
  Fields:
    price (series float)
    price_prev (series float)
    symbol (series string)
    dte (series float)
    time (series int)
    volume (series float)
    open_interest (series float)
    expiration (series int)

CurveSummary
  Fields:
    max_time (series int)
    min_price (series float)
    max_price (series float)
    min_prev (series float)
    max_prev (series float)
Notes de version
v4

Added:
get_forward_curve_data(symbols, min_volume, spot_symbol)
  Retrieves forward curve data for a list of futures symbols and returns both
the collected contract data and summary statistics used for scaling and analysis.

For each symbol, the function requests daily data including current price,
previous price, expiration date, timestamp, and volume. Contracts are filtered
based on expiration and minimum volume criteria, except for the designated
spot symbol which is always included.

Valid contracts are stored as CurvePoint records and aggregated into a curve
array. Summary statistics such as min/max prices and the latest timestamp are
tracked in a CurveSummary object.
  Parameters:
    symbols (array<string>): Array<string> List of futures symbols forming the forward curve.
    min_volume (float)
    spot_symbol (string): Spot or underlying symbol always included in the curve.
  Returns: [array<fut.CurvePoint>, fut.CurveSummary]
Tuple containing the array of curve points and the calculated summary.
Notes de version
v5

Added:
forward_curve_contango(curve)
  Determines whether the forward curve is in contango.
Contango occurs when the next futures contract trades
at a higher price than the front contract.
  Parameters:
    curve (array<CurvePoint>): Array<fut.CurvePoint> Forward curve data.
  Returns: bool True if the curve is in contango, otherwise false.
Notes de version
v6

Adding Majora and Allowed Months for Aggs, Softs and Macro.

Clause de non-responsabilité

Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.