Hi,
I just slightly modified the SellRandom script from FinancialHacker to be able to trade multiple options assets.

In test works fine.
But when I go in Demo account on IB, in the second loop for the second asset (AAPL) the contract is always invalid.
First Asset (is always fine).
I did another test Still in IB demo account, removing the first asset(SPY), leaving only AAPL, and then the contract is valid and the trade is entered.

Is there anything I'm missing ?
Thanks for your help



// Options Test //////////////////////////

#include <contract.c>
static int LastExpiry[2];

void run()
{
int Handle=0;
BarPeriod = 1440;
BarZone = ET;
BarOffset = 15*60;
StartDate = 20140101;
EndDate = 20171001;
set(PRELOAD|LOGFILE);
PlotWidth = 1000;
PlotHeight1 = 400;

while(asset(loop("SPY","AAPL")))
{
Handle++;
assetHistory(Asset,FROM_AV|UNADJUSTED);
if(is(INITRUN))
{
char FileName[100];
sprintf(FileName, "%s_SimOptions.t8",Asset );
dataLoad(Handle,FileName,9);
}

contractUpdate(Asset,Handle,CALL|PUT);
Multiplier = 100;
int Type = ifelse(random() > 0,CALL,PUT);
CONTRACT *c=contract(Type,30,priceClose());

if(c && ContractType && LastExpiry[Handle-1] != ContractExpiry && !is(LOOKBACK))
{
contractPrint(c);
printf("n %s %s ContractType:%d ContractExpiry:%d Strike:%f LastExpiry:%d",Asset,strdate("%Y-%m-%d %H:%M:%S"), ContractType, ContractExpiry, priceClose(), LastExpiry[Handle-1]);
enterShort();
printf("n SOLD!");
LastExpiry[Handle-1] = ContractExpiry;
}
else if(!is(LOOKBACK))
{
printf("n %s %s ContractType:%d ContractExpiry:%d Strike:%f LastExpiry:%d",Asset,strdate("%Y-%m-%d %H:%M:%S"), ContractType, ContractExpiry, priceClose(), LastExpiry[Handle-1]);
printf("n INVALID!");
}
}
}