View Full Version : NT7 definition of CalculateOnBarClose
zeeee
07-21-2010, 12:33 PM
After having to jump through a few programming hoops to trigger an event close to the end of the bar in one of the other popular automated trading platforms I'm curious to work out how NT defines the end of the bar.
At the programming level it seems quite clear (CalculateOnBarClose=true!). I'm aware that it's impossible to define precisely the bar close - it has to be a point in real time but that's why I'm asking this here.
I also noticed via the backtest results that the CalculateOnBarClose event does not seem to trigger before the bar close event and the trade is registered as belonging to the next bar.
The area of concern for me is around the market close not so much the bar close. Will it be down to my chosen broker whether to accept the order command if the automated trading script triggers after the bar, and the market, is closed?
Thanks!
NinjaTrader_RyanM
07-21-2010, 12:52 PM
Hello Zeeee,
The bar closing event is indeed tied to the open of the next bar. Therefore can't know that it's been closed until a new one begins. There have been suggestions for a session ending event and this would help around market close situations. Unfortunately I can't offer any timeline on when or if this will be implemented.
Yes, it will depend on your broker whether they accept or reject the order. You can experiment with different TimeInForce options for this case. For example: They may reject an order with TIF Day if submitted after market close.
zeeee
07-21-2010, 01:14 PM
Ta Ryan, sounds definitely like something to run past the broker.
I agree, it would be nice to have a function similar to the ExitOnCloseSeconds but for OnBarUpdate (only where CalculateOnBarClose=true of course) so any script could be triggered by this event.
zeeee
07-23-2010, 03:28 PM
Hi Ryan, just want to confirm when the actual order would be sent by the strategy: immediately, or when the first tick comes in of the new bar?
NinjaTrader_Josh
07-23-2010, 04:29 PM
zeeee,
Depends what you have for your strategy settings in Tools>Options>Strategies>NinjaScript. If you select ImmediatelySubmit it will go right away. If you select WaitUntilFlat, it will wait till your strategy position is flat.
zeeee
07-28-2010, 08:08 AM
Hi Josh, I have tried changing the settings in that menu and also with the TIF settings but when I backtest (I don't have a live account yet) against indices the order will always open at the market price of the new bar rather than the close.
Is the behaviour during backtesting different?
NinjaTrader_RyanM
07-28-2010, 08:15 AM
Hi zeeee,
In a backtest, orders are submitted at the open of the next bar following the condition.
During real time this is controlled by the CalculateOnBarClose (http://www.ninjatrader-support.com/HelpGuideV6/CalculateOnBarClose1.html) settings. Orders are submitted either immediately when true or at bar close.
http://www.ninjatrader-support.com/HelpGuideV6/DiscrepanciesReal-TimeVsBacktest.html
zeeee
08-05-2010, 03:37 AM
Thanks, I understand now. It seems odd that the backtesting should behave so differently. It's bothering us a bit already - backtesting in NT doesn't reflect our forward testing.
Regards.
NinjaTrader_Bertrand
08-05-2010, 06:37 AM
zeeee, you can add finer granularity to execute your orders to with the help of the concept shown here - http://www.ninjatrader.com/support/forum/showthread.php?t=6652
zeeee
08-05-2010, 06:53 AM
Excellent, that's not unlike the solution I am using (successfully) in the other software package.
Thanks for your help!