Futures Roll and Expiry Week Shading
Futures contracts expire on a fixed schedule determined by the exchange, and traders must transition to the next contract month before expiry to maintain their position. This indicator automatically detects expiry dates and shades both the expiry week and an estimated roll week, helping traders avoid the liquidity decay and widened spreads that typically occur as a contract nears its last trading day. It is most useful for systematic traders managing multi-contract portfolios or for manual traders who want a visual reminder of the administrative deadlines embedded in the contract calendar.
//@version=6
indicator("Futures Roll & Expiry Week Shading", overlay=true)
// Inputs for expiry week shading
days_before_expiry = input.int(7, "Days to Shade Before Expiry", minval=1, maxval=30,
tooltip="Number of days before contract expiration to begin shading")
expiry_color = input.color(color.new(color.red, 75), "Expiry Week Background Color")
// Inputs for roll week shading
use_roll_shading = input.bool(true, "Shade Roll Week")
roll_day_of_month = input.int(15, "Typical Roll Day of Month", minval=1, maxval=31,
tooltip="Estimated day of month when contracts roll to next month")
roll_color = input.color(color.new(color.orange, 75), "Roll Week Background Color")
// Get days until expiration from the current futures contract
days_to_expiration = contract.expiration
// Determine if we're in the expiry week
in_expiry_week = not na(days_to_expiration) and days_to_expiration <= days_before_expiry
// Determine if we're in the roll week (simple day-of-month based estimate)
in_roll_week = false
if use_roll_shading
current_day = dayofmonth(time)
// Shade a 4-day window around the typical roll day
in_roll_week = current_day >= roll_day_of_month - 2 and current_day <= roll_day_of_month + 2 and not in_expiry_week
// Apply background shading
if in_expiry_week
bgcolor(expiry_color)
else if in_roll_week
bgcolor(roll_color)
How the code works
The indicator uses contract.expiration, a Pine Script built-in variable that returns the number of days until the current contract expires, provided the chart symbol is a recognized futures contract. When contract.expiration is not missing (i.e., when a futures contract is properly identified), the script compares this value to days_before_expiry. If the number of days remaining is less than or equal to the user-specified threshold (default 7 days), the entire bar background is shaded in red, drawing attention to the imminent deadline.
The roll week shading provides a separate visual cue based on the estimated roll day of month. Most exchange-listed futures roll on a specific day each month (e.g., the 15th for many interest-rate contracts, the 8th or 17th for equity index futures). By entering that typical roll day, the script shades bars within a 2-day window before and after that date in orange, giving traders an advance heads-up before the active contract transitions to the next month. If both conditions are true simultaneously (a rare case near the very end of a contract month), expiry shading takes priority.
Reading it on a chart
On a continuous futures chart or a single-contract chart, watch for red shading to appear as the contract enters its final trading week. This signals that liquidity is beginning to migrate to the next contract month and that unfilled orders may face wider spreads. Orange shading marks the calendar period when most traders have already rolled and when the prior month's contract is typically the least active. Contracts expire on defined dates set by the exchange; the red zone will always appear on the same calendar window each month. The orange zone highlights the transition period when volume shifts but formal expiry has not yet occurred.
Note that contract.expiration only works when TradingView's symbol library recognizes the chart as a futures contract. If using a custom or delisted symbol, the expiry detection will be inactive (no shading), and traders must rely on the manual roll-day input alone.
Limitations
Dependence on symbol recognition. The automatic expiry detection using contract.expiration requires that the exchange and contract code are properly mapped in TradingView's library. Custom symbols, delisted contracts, or mismatched ticker syntax will not trigger expiry shading, even if the contract does expire. Always verify that the chart symbol is a recognized futures ticker before relying solely on the red shading.
Manual roll day estimate. The orange roll-week shading is based on a static day of month, which is an approximation. Actual roll dates vary slightly by contract and may shift on weekends or holidays. The 4-day window (two days before and after) is a convention rather than a precise rule; different traders and institutions roll on different days within the month. The roll date input is a reference point only, not a guarantee of when the contract will actually transition liquidity.
No historical expiry data. When viewing historical bars from months in which the contract has already expired, contract.expiration will be missing or zero, and no shading will appear. The indicator only provides forward-looking information on the current or live contract month.
Overlay assumption. The indicator works as an overlay (background shading on the price chart). It does not create alerts, place orders, or modify position management; it is purely visual and requires manual trader action.
Key definitions
Contract expiration: The final day on which a futures contract may be traded on an exchange, after which the contract ceases to exist and all open positions are settled by delivery or cash.
Roll or contract roll: The practice of closing or liquidating a position in an expiring contract month and simultaneously opening an equivalent position in the next contract month to maintain continuous market exposure.
Roll date: The calendar date or week when traders typically transition from one contract month to the next; occurs before formal expiry to avoid the liquidity drain and settlement mechanics of the expiring contract.
Days to expiration: The number of calendar or trading days remaining before a futures contract reaches its official expiry date and stops trading.
Liquidity migration: The shift of trading volume and open interest from an expiring contract month to the next month as traders and institutions roll their positions.
References
- CME Group, "Contract Specifications and Trading Hours," CME Globex Reference (2025). Https://www.cmegroup.com/
- Chicago Board of Trade (CBOT), "Treasury Futures Contracts," CBOT Product Guide (2025). Https://www.cmegroup.com/markets/products/interest-rates/index.html
- Intercontinental Exchange (ICE), "Energy Futures and Options," ICE Rulebook and Contract Specifications (2025). Https://www.theice.com/products/futures
- TradingView, "Pine Script Reference: contract object," TradingView Documentation (2025). Https://www.tradingview.com/pine-script-reference/
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-10-18. Educational research on historical data, not financial advice.
Keep reading
Spread Tracker: Two Futures Contracts
Free open-source Pine Script indicator: spread tracker between two related futures contracts. Full code and a plain-English walkthrough.
New High / New Low Breadth
Free open-source Pine Script indicator: new high/new low breadth proxy for a symbol basket. Full code and a plain-English walkthrough.
Floor vs Camarilla Pivot Points
Free open-source Pine Script indicator: pivot points: floor trader vs Camarilla comparison. Full code and a plain-English walkthrough.