Thank you Petra. To play with it, I removed the SMA calculation and then things run as expected.

However, I am still confused with what a Bar really refers to (and therefore BarPeriod). I thought it was a time interval, say 1-minute, and regardless of the gaps in the history I have, it will be a fixed number of them between StartDate and EndDate.

But, it seems that it refers to the actual historical bars, more like candles actually. Is this correct? So in my case, a daily candle (when there are no minute candles), is treated as 1 bar, much the same as an intraday 1-minute candle. Therefore, when I set Lookback to 200, that can refer to a varying amount of time actually, depending on the available history before the StartDate?

Am I understanding this correctly?

Also, I am unsure what you mean by "calculate sma by script". Do you mean I manually have to build a series of just daily prices?