There's a QCAlgorithm.LiveMode property that's true if running in live mode.

They need something similar to tell if it's running as a backtest, and optimize, and if it's in the debugger.

thanks - dave