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 07-10-2012, 04:02 AM   #1
tickling
Member
 
Join Date: Oct 2009
Posts: 64
Thanks: 9
Thanked 5 times in 4 posts
Default Calculate on bar close on range bars

Hello

1. I have a strategy that runs on range bars with COBC=true. When exactly is OnBarUpdate() called ? is it run on the first tick of the new bar, for the old bar ?

2. I need this strategy to run with COBC=false and get some info every tick, yet I do not want it to go through all the end of bar calculations. How do I do that programatically ? Should I use "FirstBarOfTick" and if true go through the end-of-bar-calculations, else go trough tick calculations ? Is there a better way ?

3. If I need this strategy to read OnMarketUpdate event, how can I programatically know if it is the start/end of a range bar ? The documentation for FirstTickOfBar says it is only available in OnBarUpdate().

Thanks
tickling is offline  
Reply With Quote
Old 07-10-2012, 04:22 AM   #2
NinjaTrader_Joydeep
NinjaTrader Customer Service
 
NinjaTrader_Joydeep's Avatar
 
Join Date: Dec 2011
Location: India
Posts: 3,286
Thanks: 580
Thanked 546 times in 541 posts
Default

Hello tickling,

1. COBC is called on the first tick of the new bar, which is also where the previous bar ended.

2. Yes, you have to calculate it at the FirstBarOfTick. Please refer to this sample code which demonstrates it further http://ninjatrader.com/support/forum...ad.php?t=19387

3. OnMarketData and OnBarUpdate runs on different threads. As such FirstBarOfTick cannot be accessed from OnMarket Data. Unfortunately there are no native methods in OnMarketData to obtain that information.

Please let me know if I can assist you any further.
NinjaTrader_Joydeep is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Joydeep for this post:
Old 07-10-2012, 07:43 AM   #3
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,214
Thanks: 24
Thanked 1,229 times in 1,000 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by tickling View Post
Hello

1. I have a strategy that runs on range bars with COBC=true. When exactly is OnBarUpdate() called ? is it run on the first tick of the new bar, for the old bar ?

2. I need this strategy to run with COBC=false and get some info every tick, yet I do not want it to go through all the end of bar calculations. How do I do that programatically ? Should I use "FirstBarOfTick" and if true go through the end-of-bar-calculations, else go trough tick calculations ? Is there a better way ?

3. If I need this strategy to read OnMarketUpdate event, how can I programatically know if it is the start/end of a range bar ? The documentation for FirstTickOfBar says it is only available in OnBarUpdate().

Thanks
Use a boolean class variable that fires on FirstTickOfBar and off on the next tick, and query it from OnMarketData().

As the OnBarUpdate() and OnMarketData() events sequence is not guaranteed, it being asynchronous, with no lock, it will not be perfect, but it should be close enough. If you need microsecond accuracy, then you are probably on of those mega rich High Frequency Traders, so NT is not your cup 'o tea anyway.
koganam is online now  
Reply With Quote
The following user says thank you to koganam for this post:
Old 07-10-2012, 08:17 AM   #4
tickling
Member
 
Join Date: Oct 2009
Posts: 64
Thanks: 9
Thanked 5 times in 4 posts
Default

Thanks ! The "close enough" solution is probably good enough ... will give it a try.
No mega rich HFT here
tickling is offline  
Reply With Quote
The following user says thank you to tickling for this post:
Reply

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
Calculate On Bar Close/Open-Low-High-Close relationship jkmott59 Indicator Development 6 04-10-2012 10:47 AM
Range bars, strategy and close on bar coolmoss General Programming 5 03-05-2012 12:04 PM
RE: calculate the sum of a specified range of bars Shawn General Programming 2 11-10-2011 02:21 PM
Calculate on bar close = false but only signal on close of bar gyoung Indicator Development 3 10-26-2011 11:15 AM
Calculate on bar close unclelou Charting 1 03-25-2009 05:43 PM


All times are GMT -6. The time now is 05:13 AM.