This is how I managed to build a daily SMA, however this seems extremely fragile to me (for backtesting). For example, if there were no trades at 16h ET, there would be no bar and we wouldn't produce a daily close. There must be a more robust way of doing this, no? Is there some way to track an internal clock during backtesting?
Code:
// capture NYSE market close and the Friday close that falls on Sunday 23h UTC
static int numSkippedBars = 0;
if(lhour(ET, 0)==16 || hour(0)==23) {
	TimeFrame = min(-1, -numSkippedBars);
	numSkippedBars = 0;
}
else {
	TimeFrame = 0;
	numSkippedBars++;
}
vars dailyPrices = series(priceClose(0));
vars sma = series(SMA(dailyPrices, 200));




I also tried this, but it doesn't work correctly and I'm not sure why. It correctly gets the daily close when there are intraday bars and on the first day of the week only. Everything else gets skipped (TimeFrame=0). Why?
Code:
FrameOffset = 21*60-dst(ET, 0)*60;
TimeFrame = frameSync(1440);

vars dailyPrices = series(priceClose(0));
vars sma = series(SMA(dailyPrices, 200));




What would be a proper way to build a daily close series?
Thank you.