NinjaTrader Support Forum  

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

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 09-05-2012, 12:53 PM   #1
PDT123
Junior Member
 
Join Date: Oct 2009
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default OnBarUpdate

Is there a anyway to know if when OnBarUpdate is called it is from live data or historical data?
PDT123 is offline  
Reply With Quote
Old 09-05-2012, 12:59 PM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

PDT,

Yes! This is called "Historical" and is a variable.

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

Please feel free to ask us questions any time, we are happy to answer.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 09-05-2012, 03:28 PM   #3
PDT123
Junior Member
 
Join Date: Oct 2009
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Adam,

Thanks for the prompt reply.

I am creating an indicator that loads a second instrument with a different timeframe. Everything works great on live real time data but if the chart is reloaded and for all previous sessions it looks like the data is exactly one bar off (before) from the charts instrument.

Any thoughts on why?

Thanks,
Dan
PDT123 is offline  
Reply With Quote
Old 09-05-2012, 03:30 PM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

PDT,

I am not sure here, could you possible post your code and/or some screen shots?

http://take-a-screenshot.org/
NinjaTrader_AdamP is offline  
Reply With Quote
Old 09-05-2012, 10:27 PM   #5
PDT123
Junior Member
 
Join Date: Oct 2009
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Adam,

I have spent some time trying to figure out what is going on and it looks like when the main instrument is loading historical data on the chart it is only calling OnBarUpdate once at the bar close. I am using a 2000 tick chart.

I used the BarsInProgress == 0 and printed every time that OnBarUpdate was called and the times matched the ending times of that bar.

9/5/2012 8:29:59 AM
9/5/2012 8:30:45 AM
9/5/2012 8:32:11 AM
9/5/2012 8:33:58 AM
9/5/2012 8:35:52 AM etc.

This is on the ES so there are lots of ticks going off in between.

Can you explain how the historical data is processed. I assumed that it would call OnBarUpdate for each tick or change.


Thanks,
Dan
PDT123 is offline  
Reply With Quote
Old 09-06-2012, 06:08 AM   #6
PDT123
Junior Member
 
Join Date: Oct 2009
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

I do have CalculateOnBarClose set to False.
PDT123 is offline  
Reply With Quote
Old 09-06-2012, 06:43 AM   #7
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

Hi Dan, for historical processing it would not matter how CalculateOnBarClose is set - it would be 'true' per default here, as the OnBarUpdate() is called for each completed bar, not for each tick (as it would be in realtime / market replay with the CalculateOnBarClose = false).
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 09-06-2012, 08:22 AM   #8
PDT123
Junior Member
 
Join Date: Oct 2009
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Adam,

I am collecting data from the second intrument on a different time frame and putting it in a dataseries which matches the main instrument. With real time it works great but since the OnBarUpdate is only called at the end of the bar on Historical data the data I collected is put into the bar before when the new bar is created.

I assume the dataseries are added to as each new bar is created. When OnBarUpdate is called for the current bar has the next bar been added to the dataseries? Is there a way to shift the data or an easy way add it to the next bar?

Thanks,
Dan
PDT123 is offline  
Reply With Quote
Old 09-06-2012, 12:55 PM   #9
PDT123
Junior Member
 
Join Date: Oct 2009
Posts: 20
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Adam,

I just setup a second dataseries and handled the loading of the historical data differently so it is working fine now.

Thanks,
Dan
PDT123 is offline  
Reply With Quote
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
OnBarUpdate cshep Version 7 Beta General Questions & Bug Reports 2 08-18-2010 04:28 PM
OnBarUpdate eqtrader General Programming 5 07-28-2010 10:37 AM
OnBarUpdate() Rhyshaelkan General Programming 0 01-09-2010 03:11 PM
Twice through OnBarUpdate()? cybertunerone Strategy Development 4 02-08-2009 01:52 AM
OnBarUpdate SystemTrading Miscellaneous Support 3 08-20-2008 10:38 AM


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