Let’s suppose you want to trade only from 7am to 11am, and you want to make sure your backtesting and optimization is only in that range too. We’ll assume you are using 15 minute bars, and you already have a long entry rule and a long exit rule (maybe crossovers or something). Now add the following rule to the entry tab:
7am <= time <= 10:45am
Make sure the tab says “Generate a buy long order if ALL of the following are true.”
Now add the following rule to your exit tab:
time = 11am
Make sure that the the long exit tab says “Generate a sell long order if ONE of the following are true.
It does what you want. It only enters in your time frame. If you haven’t already exited, it exits at the end of your time frame. Note that you have to end buying at 10:45am so you will have the ability to exit in your timeframe at 11am. Shorts are exactly the same.
The situation does get rougher if you have multiple exit rules, all of which must be true. In that case you have to AND all those rules together so that they become one rule. It also gets rougher if you have multiple entry rules, only 1 of which must be true. In that case you will have to OR all those rules together so that they become one rule.