Find new front month

1 post / 0 new
Find new front month

I'm working on a subroutine that rolls over my positions when a contract expires or if the strategy in question just has no open position simply shifts the contract from the expiring to the new front month.
For some underlyings this is already working great but for others my routine has a hard time to find the new front month.

I use marketSearch to search for the new contract. For example am I searching for a new dax contract my routine uses the search string "DAX".
This works pretty well for most indices but if I for example want to search for the next contract for chicago wheat it is getting tricky. The symbol for wheat is just "W" and searching for just "W" will give A LOT of results that I don't want to have and my routine has to start searching in all this results for the right contract. This is doable but pretty cumbersome and it is getting worse. Like wheat there are several other symbols that cause this problem or a slight variation of it.
Having to treat all this exceptions separately is not very nice.

Has anyone solved this and come up with an elegant way to find the next front month' epic?