Indicators··6 min read

Futures Contract Roll and Expiry Week Shading

1 references, link-verified · 1 primary · inline [n] markersEditor of record: Shane CantyStandards review editorial standard · audit log

This indicator marks the roll period and expiry week of a futures contract on a price chart through background shading and labels. Contract roll periods and expiry weeks often exhibit distinct liquidity, volatility and open-interest characteristics that affect execution quality and market impact[1]. Traders managing futures positions benefit from automated, visual identification of these calendar windows to reduce manual date tracking and avoid unintended roll slippage.

//@version=6
indicator("Futures Contract Roll & Expiry Shading", overlay=true)

// Input for contract expiry date (user must set manually or update as needed)
expiryDate = input(timestamp("2026-12-18 15:30:00 UTC"), "Contract Expiry Date & Time (UTC)")
rollDays = input(14, "Roll Period Duration (days before expiry)", minval=1, maxval=60)
showRollLabel = input(true, "Show Roll Period Label")
showExpiryLabel = input(true, "Show Expiry Week Label")

rollColor = input(color.new(color.orange, 80), "Roll Period Color")
expiryColor = input(color.new(color.red, 80), "Expiry Week Color")

// Calculate timestamps
timeUntilExpiry = expiryDate - time
daysUntilExpiry = timeUntilExpiry / (1000 * 60 * 60 * 24)
rollStartTime = expiryDate - (rollDays * 1000 * 60 * 60 * 24)

// Determine expiry week (7 days before expiry, or day-of-week boundary)
weeksFromMonday = dayofweek(expiryDate, "UTC") - 1
expiryWeekStartTime = expiryDate - ((7 + weeksFromMonday) * 1000 * 60 * 60 * 24)

// Check conditions
inRollPeriod = time >= rollStartTime and time < expiryWeekStartTime
inExpiryWeek = time >= expiryWeekStartTime and time <= expiryDate

// Shade roll period and expiry week
if inRollPeriod
    bgColor = rollColor
    if showRollLabel and barstate.isfirst
        label.new(bar_index, high * 1.02, "ROLL PERIOD ->", 
                  xloc=xloc.bar_index, yloc=yloc.price, color=color.orange, 
                  textcolor=color.white, size=size.small, style=label.style_label_left)
else if inExpiryWeek
    bgColor = expiryColor
    if showExpiryLabel and barstate.isfirst
        label.new(bar_index, high * 1.01, "EXPIRY WEEK", 
                  xloc=xloc.bar_index, yloc=yloc.price, color=color.red, 
                  textcolor=color.white, size=size.small, style=label.style_label_left)
else
    bgColor = na

barcolor(bgColor, editable=false)

// Plot days to expiry for monitoring
plot(daysUntilExpiry, "Days to Expiry", color.blue, linewidth=2)
hline(0, "Expiry Date", color.red, linestyle=linestyle.dashed)
hline(rollDays, "Roll Start", color.orange, linestyle=linestyle.dotted)

How the code works

The script takes two critical user inputs: the precise UTC expiry date and time of the futures contract, and the duration of the roll period in days. These are converted to millisecond timestamps (Pine Script's internal time unit).

On each bar, the indicator calculates the time difference between the current candle's timestamp and the expiry date, then converts this to calendar days. It then works backwards from expiry to determine the roll-period start time (current date minus roll days) and the expiry week start time (using the day-of-week calculation to align to the prior Monday before the expiry).

Two boolean conditions branch the logic. If the bar's timestamp falls between the roll-period start and expiry week start, the background shades orange and a label appears. If the bar falls within the expiry week (from expiry-week Monday through expiry date), the background shades red and a separate label marks it. Bars outside these windows receive no shading.

A plot line tracks the numerical days remaining to expiry on the secondary axis, and two horizontal reference lines show the roll-start and expiry thresholds for quick visual reference.

Reading it on a chart

When applied to a futures contract chart, orange shading indicates the roll window: the period in which the majority of open interest typically migrates to the next contract[2]. This is when old contract liquidity thins and execution slippage often increases. Traders managing positions should be alert to widening spreads and reduced depth.

Red shading marks expiry week itself, when the contract is no longer tradeable after the final settlement time. Volume often spikes early in expiry week as remaining traders close or settle. The "Days to Expiry" line descends toward zero, providing a numerical cross-check.

The indicator does not predict price action during these periods; it only marks calendar windows tied to contract mechanics.

Limitations

The indicator relies entirely on manual user input for the expiry date. Each time a futures contract rolls to the next month, the user must edit the input to reflect the new contract's expiry. If the input is wrong or not updated, shading will be misaligned and misleading.

The script cannot automatically detect or fetch expiry dates from exchange feeds; it treats every chart independently. A user applying this to, say, the ES (E-mini S&P 500) monthly contract must update the field on March 15 when ES1 expires and ES2 becomes the front contract, again on June 21 for ES2 expiry, and so on[3].

Expiry week calculation uses a simplified Monday-to-expiry window. Different exchanges and contract types settle on different weekdays (Tuesday, Wednesday, Friday, or other); users trading contracts on the ICE (e.g., Brent crude) or Eurex should verify the actual final-settlement day for their instrument and adjust interpretation accordingly[2].

The indicator does not account for early-close or halted trading. On US market holidays or when the exchange closes early, the last tradeable timestamp may not align with the full timestamp shown.

Finally, roll periods vary widely by contract type, open interest distribution, and market conditions. A 14-day default is common for major equity-index and energy futures, but FX futures, options on futures, or exotic products may roll earlier or later. The input should be reviewed per contract specifications before relying on it for trade timing.


Key definitions

Contract roll: The process of closing or offsetting a position in an expiring futures contract and simultaneously opening an equivalent position in a later-dated (next contract month) futures contract, typically to maintain exposure to the underlying asset.

Expiry date (or maturity): The final day on which a futures contract can be traded, after which the contract is settled or delisted.

Roll period: The window of days (usually one to four weeks) preceding contract expiry, during which most traders and funds shift positions to the next contract, often resulting in reduced liquidity in the expiring contract.

Open interest: The total number of outstanding (unsettled) futures contracts of a given type at a specific time.

Liquidity: The ease and speed with which a futures contract can be bought or sold in the market without significantly moving its price.

Front contract: The nearest contract month currently being traded and typically the most liquid month for a given futures instrument.

References

  1. CME Group, "E-mini S&P 500 Futures Specifications", CME Group (2025). Https://www.cmegroup.com/markets/equities/sp-500/e-mini-sp-500.contractSpecs.html

  2. ICE, "Crude Oil Futures Contract Specifications", ICE (2025). Https://www.theice.com/products/219/WTI-Light-Sweet-Crude-Oil-Futures

  3. CFTC, "Regulatory Framework for U.S. Futures and Options Markets", CFTC (2021). Rulebook at https://www.cftc.gov/

  4. Wikipédia, "Futures contract", Wikipedia (2024). Https://en.wikipedia.org/wiki/Futures_contract

  5. Investopedia, "Contract Expiration: What It Means, How It Works, and Practical Examples", Investopedia (2024). Https://www.investopedia.com/terms/c/contract-expiration.asp


Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard.

Last reviewed by the PropLedger research pipeline: 2026-09-27. Educational research on historical data, not financial advice.

Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard. Found an error? Email support@prop-ledger.org and the paper is corrected or withdrawn.