Just watch the volumes. I go as soon as the forward contract is active enough to trade. Usually, a Monday of the week the next contract volume flips to greater than the current. Also you can go back and see the flip historically. Never wait until the volume dries up.
Here's a good example for CL at the moment... That is all you need on your trading platform. A live look at trading volume. You do not need to freak out about the exact days. (As an aside, it is interesting that May and June CL are the same price this far from expiration. This is practically backwardation. But I digress.) The roll you should see on April 20th. Get out on the 19th and you'll have no worries about the spread.
As I posted previously set up a watchlist on CME site and it is done automatically. No need to check annnnything but that page. For instance, my top entry NQ which shows current front month NQM3 will, once contract rolls in a couple of months - on the correct day, then show NQU3 ....... without me lifting a finger.
Thanks for taking the time to reply @Overnight. You failed to read my OP through to the end... "I have an automated system for trading various Index and Commodity futures and I'd like to program this change so it is handled automatically." Though I have an idea of how the contract switch is determined (i.e. by volume), to automate the switch, I need a reliable data source that I can query using an API (application program interface).
I like this option for manually checking on a daily basis. I did go ahead and setup my Watchlist on CME. I am still looking for an online data source that my program can query and handle this for me automatically.
I have a few automated programs running on CQG. I use the symbol and it does the rest for me with the options below. Are your systems day trade systems or swing? for the indices I would switch the Monday few days before the actual expiration on Friday. Let me know what other markets and i can try to help as well.:
There is about a One Week period - with Both Contracts open - I switch - when the Volume on the New Contract - is Larger than on the Old Contract. It is really that Simple. I do NOT use the Continuous Contract.
CME Reference Data API https://www.cmegroup.com/trading/market-tech-and-data-services/cme-reference-data-api.html ?
I have a program running to handle the rollover automatically. It uses IB as data source. Several weeks before the expiry of a contract it starts to compare its daily volume with that of the next contract. When the next contract has a trade volume exceeding a certain limit (I believe I'm using 70% of the current contract) then it will act.