Modified for backtesting and scripting