Loop through option chain

Posted By: strimp099

Loop through option chain - 01/29/21 03:04

Greetings,

I'm trying to loop through every contract in a chain for a given bar.

Code
void run()
{
    	// load today's contract chain
	if(!contractUpdate(Asset,0,CALL|PUT)) return;
	
	int i;
	for (i = 0; i <= NumContracts; i++)
	{
		CONTRACT* C = &Contracts[i];
		
		contractPrice(C);

		printf("\n%f",ContractAsk);
	}

}


This just prints 0.00000. I've already confirmed my .t8 file contains the chain data by exporting to CSV and munally checking.

What is the proper way to iterate through the options chain?
Posted By: strimp099

Re: Loop through option chain - 01/29/21 07:38

Per usual immediately after posting a question, I sorted it. Need to select the contract first so can do it a few ways

Code
	int i;
	for (i = 1; i <= NumContracts; i++)
	{
		
		contract(i);
		
		printf("\n%f - %f",ContractBid,ContractAsk);
	}


or

Code
	int i;
	for (i = 0; i < NumContracts; i++)
	{
		CONTRACT* C = &Contracts[i];
		
		contract(C);
		
		printf("\n%f - %f",ContractBid,ContractAsk);
	}
© 2024 lite-C Forums