Order of Intraday Trade Execution - TradeStation v AmiBroker

Not sure if many people here remember much about TradeStation 2000i but it was possible to build a daily chart by loading, say, 5 min data, compress that to a daily chart, run your system code on the daily chart (so that trading levels, etc were all generated from daily OHLC) and then check a '5min' box in the backtest settings so that the order of execution of trades would be checked against 5min data while the system itself was running on daily data. That meant TradeStation effectively 'looked inside' the daily bar to check the order of execution of trades against what really happened in the market on a lower timeframe.

This was really handy if you were running a system that has a limit buy entry below the market and an If-Done limit sell exit above the market. In this case you could finish the session either with a profitable trade (if the buy entry limit was triggered first and the If-Done sell limit was triggered second), or a large loss if the market traded up to the If-Done sell limit and then traded down through the buy entry limit and kept selling off.

On daily data there is no way to determine which outcome actually happened, so TradeStation used to make all sorts of assumptions about the open being closer to either the high or the low and by using things like BouncingTicks to try and simulate intraday volatility.

I have been looking into how it might be possible to run a system on daily data built from hourly data and then have AmiBroker 'look inside' the bar to determine the order of trade execution based on intraday data rather than trying to code assumptions. I can load up hourly data & set Periodicity to daily so that the system runs on daily data but this changes the OHLC arrays to daily as well and does not check the order of execution of trades on the intraday data, from which the daily data the system is running on, is built.

I have read up on TimeFrameSet() and it seems you cannot reference a lower timeframe from a higher one. The only way to do this is in AmiBroker, I think, is to load the hourly data, set Periodicity to Hourly in the Backtest Settings and then have the code convert all arrays to daily using TimeFrameSet(). Then you run that portion of the system code which needs daily data.

From there you use TimeFrameRestore() to go back to Hourly and then run the portion of code which controls entry and exit to make sure the order of execution of your trades reflects reality.

My question is, does anyone know if it possible in AmiBroker to run a system on daily data constructed from hourly data so that the system calculations are correct, but then revert back to hourly data to run the code which physically checks and executes trades so that the order of execution is what would have really happened in the market? Or is coding the system to operate on intraday data, setting Periodicity to the lower timeframe and using TimeFrameSet() to switch between timeframes the only way?

Any assistance or clarity on this would be greatly appreciated!

Generally AmiBroker does not make any assumptions as to what happens inside bar. It simply does what you tell it to do via Signal and Price variables (Buy and BuyPrice) for example.
It is up to you to code your formula so both signal and price variables are correct.

If there is more than one signal per bar per symbol, the conflict is resolved using rules and user-definable settings described in the manual Portfolio-level back testing

If you want to "look inside the bar" you have to set your Analysis periodicity to HOURLY (or other intraday) and use TimeFrameSet( inDaily ) to produce your DAILY signals in the formula
then expand those signals from daily to hourly (or other).

It is precisely described in the manual:

That way you can act on daily signals and have control over what is happening inside day based on intraday data.

Many thanks Tomasz.
Sounds like in this instance I would load hourly data, set Periodicity to hourly, use TimeFrameSet() to calculate daily arrays, then TimeFrameRestore() to bring things back to hourly.
From there, a loop through all bars checking for daily boundaries in the data to run execution?

Just directly calculate signals and expand them as described in manual Multiple Time Frame support

Generally you do not need a loop. Everything is array wise anyway.

1 Like