Is there any parameter that I can set to determine the regular trading hours for my algo, ie "Don't trade before this time and exit all positions at that time".

Currently I'm doing this manually like so

//Only enter trades during these hours
if (hour() >= 9 && minute() >= 0 && hour() <= 17 && minute() <= 29)
{
...
enterLong();
...
}

if (hour() >= 17 && minute() >= 30)
{
exitLong();
}