I made a work-around for this that seems to be working reliably enough for me. (I consider it a convenience rather than mission-critical.)

It involves using the system() command to kick off another Zorro instance shortly after the TWS restart, and quit() to kill the original one.

My implementation is likely sub-optimal, so comments welcomed. (But, no need to lecture me about global variables.)

I am running 64-bit Zorro C++ scripts on a Windows 11 machine, with an S-level license.

The following code is pieced together from the various functions where it actually resides and hasn't been tested in this exact form, so consider it just a sketch of concept. The core commands are in the last few lines, the rest is infrastructure.

-----------------------

// Globals
int Last_Started_Day, UTC_offset;
bool SOD_Business, SOD_Business Done, EOD_Business, EOD_Business_Done; // SOD = start of day, EOD = end of day
string State_File;

DLLFUNC void main()
{
// Delay to ensure previous Zorro instance has ended
if (is(TRADEMODE) && is(COMMAND))
{
printf("10 second delay for Zorro instance handoff...");
wait(10000);
}

State_File = "Data\\My_State_File.csv";

// other main() stuff....

}

DLLFUNC void run()
{
if (Bar == StartBar)
{
printf("\n");
printf("\nLoading State File...");

// Script-wide variables
Last_Started_Day = (int)(getvar(State_File, "Last_Started_Day"));
EOD_Business_Done = (bool)(getvar(State_File, "EOD_Business_Done"));

// other state stuff....
}

// TIME ZONE OFFSET
if (dst(EST,0)==1)
{
UTC_offset = -4;
}
else
{
UTC_offset = -5;
}

start_time = 0400 - UTC_offset*100;

// Daily business
SOD_Business_Done = day(0) == Last_Started_Day;
SOD_Business = tod(0) >= start_time && tod(0) < 2300 && !SOD_Business_Done;

if (SOD_Business)
{
Last_Started_Day = day(0);
SOD_Business_Done = true;
EOD_Business_Done = false;

// other start of day stuff ...
}

int EOD_time;
bool EOD_Window;
if (dst(EST,0)==1)
{
EOD_time = 2350;
EOD_Window = tod(0) >= EOD_time;
}
else
{
EOD_time = 50;
EOD_Window = tod(0) >= EOD_time && tod(0) < 200;
}

// TWS daily restart should be set for slightly before the EOD_time. E.g. currently I use 00:30 GMT

EOD_Business = EOD_Window && !EOD_Business_Done;

if (EOD_Business)
{
if (is(TRADEMODE) && Bar > StartBar && !EOD_Business_Done)
{
login(4);
EOD_Business_Done = true;
putvar(State_File, "EOD_Business_Done", (var)(EOD_Business_Done));
wait(10000);
system("Zorro64.exe -trade My_Script.cpp");
quit("!Restarting Zorro session to cope with IBKR lockout.");
}
}

}

Last edited by Jack_Zodiac; Yesterday at 21:13.