Trying to create SMA-40 from intraday 5-min data. The data includes extended hours. I would like SMA-40 to be formed from yesterday's and today's regular sessions' data, excluding overnight hours. So far, I have been unsuccessful not to include hours from 16:00 pm to 9:30 am.

See my code. I would appreciate any advice.