To make this more concrete, I have the following minimal example that reproduces the issue.
Happy to provide the .t8 I am using on request (was blocked from attaching it to this post).
I hesitate to say the issue is a bug but at least there seems to be something inconsistent in the handling of contracts/trades?


Code
#include <contract.c>

#define HISTORY_DIR "History\\temp\\*_HistoricalFutures.t8"
#define ASSET_FILE "History\\temp\\AssetList.csv"

var equity;
int open_expiry;
int n_runs;
int j;

void run()
{
	set(PLOTNOW|LOGFILE);
	StartDate = ifelse(Live,NOW,19980715);
	EndDate = 20010901;
	BarPeriod = 1440;
	LookBack = 0;
	Verbose = 3;
	
	set(PRELOAD);
	History = HISTORY_DIR;
	assetList(ASSET_FILE);
	asset("W-FUT");
	
	n_runs += 1;
	
	Capital = 100000.00;
	equity = Capital + ProfitTotal;
	
	int thisdate = year(0)*10000 + month(0)*100 + day(0);
	printf("\n--> %d, capital = %f", thisdate, equity);
	
	// load futures
	int nfound = contractUpdate(Asset,0,FUTURE);
	
	// check contracts directly
	var prce_curr;
	for(j=1; j<= nfound; j++)
	{
		prce_curr = contractPrice(contract(j)); // access contract via index in chain
		printf("\n--> contract expiry %i, strike %f, ask %f, bid %f, price %f", ContractExpiry, ContractStrike, ContractAsk, ContractBid, prce_curr); // --> all ok
	}
	
	// check explicitly for contract of open trade
	CONTRACT* ctrptr;
	if(open_expiry)
	{
		ctrptr = contract(FUTURE, open_expiry, 0); // access contract via specifying expiry and strike
		if(ctrptr == 0)
			printf("\n--> open expiry %i but no contract found", open_expiry); // --> gets hit
		prce_curr = contractPrice(ctrptr);
		printf("\n--> contract expiry %i, ask %f, bid %f, price %f", ContractExpiry, ContractAsk, ContractBid, prce_curr); // --> all zero
	}
	
	// check contracts via open trades
	int pos_curr;
	var dte_curr;
	for(current_trades)
	{
		ctrptr = contract(ThisTrade); // access contract via trade object
		if(ctrptr == 0)
			printf("\n--> existing trade but no contract found");  // --> gets hit
		pos_curr = contractPosition(ThisTrade);
		prce_curr = contractPrice(ThisTrade);
		dte_curr = contractDays(ThisTrade);
		printf("\n--> existing pos %i, price %f, underlying %f, expiry %f", pos_curr, prce_curr, TradeUnderlying, dte_curr);  // --> prce_curr is zero, but strangely, pos_curr, TradeUnderlying, dte_curr are all ok
	}
	
	// exit open trade
	for(open_trades)
		exitTrade(ThisTrade);
	
	// enter new trade
	int first_expiry;
	j = 1;
	while(!first_expiry && (j <= nfound))
	{
		contract(j);
		if(ContractExpiry > thisdate)
			first_expiry = ContractExpiry;
		else
			j += 1;
	}
	printf("\n--> %d, first non-expired contract is %i=%i", thisdate, j, first_expiry);
	if(n_runs > 1)
	{
		contract(j);
		enterLong(pow(-1,n_runs));
		open_expiry = first_expiry;
	}
	
	if(n_runs >8) quit("Ok!");
}




any advice much appreciated!