NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 04-05-2012, 08:31 PM   #1
jeronymite
Junior Member
 
Join Date: Apr 2012
Posts: 16
Thanks: 3
Thanked 3 times in 2 posts
Question Order methods vs bar closure

First situation: According to the NT7 Manual, OnBarUpdate is called either on the close of the current bar or on every tick, depending on the setting of CalculateOnBarClose.

Reading that literally, if CalculateOnBarClose is true, I would expect that OnBarUpdate would only be called once every time a bar is completed. So, if on a 5 minute chart, once every 5 minutes exactly at the 5 minute mark.

First observation: I see trades being entered at intra-bar times even with CalculateOnBarClose set to true.

First question: What is the correct behaviour to expect for OnBarUpdate in relation to CalculateOnBarClose and ticks?

Second situation: According to the NT7 Manual, once a trade is entered with a managed entry method (e.g. EnterShort), it must be re-entered every time OnBarUpdate is called or the position will be cancelled. That implies that the conditions that were tested to initiate the entry must remain true throughout the life of the position.

Second observation: Trades persist even after the initial entry conditions have changed.

Second question: What is the actual behaviour of the managed approach in this respect?

Thanks for your kind advice.
jeronymite is offline  
Reply With Quote
Old 04-06-2012, 01:20 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,416
Thanks: 252
Thanked 978 times in 961 posts
Default

jeronymite, welcome to our forums:

Correct is that the bar update with CalculateOnBarClose = true would only be called once your bar is completed, it would not update with intrabar ticks seen then - however you would need to keep in mind NT is event based and not time based, so if you see no trade for example then there would also be no bar update seen. In a fairly liquid market though it would be hitting your time stamp expectations 99% of the time normally.

Trades can be entered intrabar, as the order is send for example on the bar close, but would be working for the bar then, so you could definitely see an intrabar fill here.

Trades will persist unless you exit them or the ExitOnClose handling set per default would take over, the will not be closed automatically by NT, the part of the manual you read concerns entries with non market orders - those would be expiring on the bar they were placed on if not filled. So that meaning then: if you trade condition for entry is still true and your limit order expires, you would need to resubmit then on the next bar until filled.
NinjaTrader_Bertrand is online now  
Reply With Quote
Old 04-06-2012, 01:26 AM   #3
jeronymite
Junior Member
 
Join Date: Apr 2012
Posts: 16
Thanks: 3
Thanked 3 times in 2 posts
Default

Thanks, Bertrand. That's very helpful.

Now, if I want to completely duplicate the behaviour of Backtest in the Live environment, I would really be saying that I want all actions (enter, exit, stop loss, profit target,etc) to be calculated and therefore actioned ONLY at bar close, since that is the only information that Backtest has, right?

So, how would I implement that in the live environment? I can set CalculateOnBarClose to be true at the start of Initialize() but is that sufficient?

Thanks!
jeronymite is offline  
Reply With Quote
Old 04-06-2012, 01:32 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,416
Thanks: 252
Thanked 978 times in 961 posts
Default

You're welcome - CalculateOnBarClose in backtesting will always be 'true'.

This will not change how orders are filled live - there's simply a difference in backtesting vs live trading, backtesting being a close approximation, but of course market dynamics are always realtime only and not known in advance.

You can backtest in Market Replay to be able to see how your strategy fares with recorded realtime data and thus having access to the tick formation of the replayed bars for better simulated fills, stops...

http://www.ninjatrader.com/support/h...ket_replay.htm

That would be the recommending cycle to go through before trading live with a script.
NinjaTrader_Bertrand is online now  
Reply With Quote
The following user says thank you to NinjaTrader_Bertrand for this post:
Reply

Tags
calculateonbarclose, intrabar, onbarupdate

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Order methods ohjob Automated Trading 3 03-07-2011 08:07 AM
Help with Order methods. ts_gordo Strategy Development 4 01-27-2010 02:54 PM
Please add a Z-Order to most of the Draw... Methods David Lean Suggestions And Feedback 1 01-09-2010 10:21 AM
The Source Code behind Order Methods brima Strategy Development 2 07-29-2008 04:47 PM
Using StopLimit Order Methods tquinn Strategy Development 1 01-14-2007 03:18 AM


All times are GMT -6. The time now is 04:47 AM.