SetTradeDelays(0, 0, 0, 0) Confusion

I am confused about when exactly a trade occurs given the trade delay given the following
piece of code below.

I have two questions that are given below.

NOTE: I am using Intraday 1-minute data.

SetTradeDelays( 0, 0, 0, 0 );

Buy = ConnorsRSI(paramLenRSI,paramLenUD,paramLenRank) < 30
  AND Close > MA(Ref(Close, -1), 200) 
  AND ClosingRange() <= 15
  AND MA(V, 21) >= 1000000
  AND ADX(10) > 30
  AND C >= 10.0;

By the definition in the manual, it says "Trade Current Bar on CLOSE...".

Q1) So, to be clear, does this mean, given 1 minute intraday data that at the END of a given 1-minute interval,
it would Buy on the Close ? Is this correct?

Q2) In addition, does this also mean, in the Backtest report when AmiBroker says it bought a stock at 9:30 am,
that in reality, what is happening is that at the END of the 1-min interval (e.g, 093059), it buys the stock. So, it actually waits about 1 minute to buy the stock? (I.e., it really bought the stock around 9:30:59 am) is this a correct assumption?

Hopefully, my question makes sense...

Thanks in advance...

If you have 1min data in DB and you are also running the backtest on 1min data, how many OHLC values do you have?
Or from another angle what is the Close or ( O H L for that matter) at

  1. 093000
  2. 093029
  3. 093044
  4. 093059

If you think all array values are the same then bingo.

Now whether AB waits for 59sec or 10s or 40s is not relevant anymore in backtest.
Just because you know there are 60secs in a minute you perceive this, but backtester doesn't.

In RTD, you'd fire trades instantaneously :slight_smile:

1 Like

I see your point and it makes some sense...

But what about the following code that uses the variable Close, which could dramatically
change between the OPEN and CLOSE of an interval of 1 minute?

Would this mean it would make more sense to trade at the END (i.e., at the CLOSE) of the 1 minute interval? Since it will use that end value in determining a Buy?

The technical implementation of the Backtester code will only be known to TJ, but although you got most of it cleared, you're still in a bit of a doubt.

Basically, in another way, think of it as if the system does not see or know that there are seconds, so there is no instance of seconds as far as its concerned.

In a 1min TF, a 200 MA will be on 200 Close bars, so those aren't seconds, those are 200 min bars.

So if Exchange opens at 9AM, and we're talking about 9:30AM, then 170 bars will be from the last part of previous day.

From you code, are you thinking 200MA in terms of seconds bars and a variation of 60? Again the price is same through all the seconds but the system doesn't know there are seconds bars.

Finest grain is 1min.

1 Like

The backtester uses periodicity set in the settings. So if you use 1-minute periodicity, as mentioned above, the granularity (resolution) is 1-minute and the system does not use anything beyond that. So backtester will just use the close of 1-minute candle as reported by data source. If you care about exact seconds, you need to backtest using 1-second interval.

For all practical purposes, if you use signals generated using close of current candle, it is advised to use trading on next bar open, or if you for some reason use no delay, account for (large) slippage as in practice you won't know bar close until the bar is already complete and you can't trade on that exact close, so you have to calculate your indicators prematurely (before real close to place the order that has chances to be filled)