I might be able to make a tutorial based on this. (I'm writing a book right now.)
Short answer: For backtesting, remember that the bar is not formed until the end of the trading day. So if you want to trade market open, define the trade on the previous trading day and change your Fill options. And to trade market close, trade the same day with a different fill option.