NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM 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 01-11-2012, 02:32 AM   #1
gena72
Junior Member
 
Join Date: Dec 2011
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default Load historical data from a strategy?

Hello,

I need to pre-load 1 week of 1-minute historical data for selected instrument(s) when my strategy starts. Ideally, I'l like to populate the same DataSeries already selected with Add().

Is there a way to accomplish this programmatically? Of cause, I can accomplish this through "extrernal" calls, but I'd like to use the same historical data managemer/connector already present in NT.

Thank you.
gena72 is offline  
Reply With Quote
Old 01-11-2012, 02:47 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Hello gena72, unfortunately you could not load data programmatically, it would be the same lookback applied by NT as for your primary series on which the strategy is run.

Another approach can be looking into the Pivots indicator that loads the data asyncronously, but unfortunately the methods used would not be supported by us.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-11-2012, 02:57 AM   #3
gena72
Junior Member
 
Join Date: Dec 2011
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default

Hello,

Thank you for explaining this. Setting a lookback for, let's say 5 days, will pre-load the main DataSeries with historical data for selected instrument (and fetch it if necessary)?
For instance, 5 days, is approximately 2500 bars, Will I be able to use Close[2500] inside the strategy?
gena72 is offline  
Reply With Quote
Old 01-11-2012, 03:02 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Yes, you can access the historical data via the index in your strategy, however you would need to ensure to not attempt to access the data too early, as the OnBarUpdate() method is processed sequentially from left to right you otherwise run into situations where there's no data for x bars back is available...the most obvious being the CurrentBar = 0, so the first bar of the chart if you attempt to access Close[1] here you're getting an error returned from NT and the script would be terminated.

http://www.ninjatrader.com/support/f...ead.php?t=3170
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-11-2012, 07:08 AM   #5
gena72
Junior Member
 
Join Date: Dec 2011
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default

Let me get this straight. If I use a "lookback" function, onBarUpdate() will be called starting from which bar? The first real-time bar coming from the exchange (in which case CurrentBar > 0), or from the oldest bar loaded from historical data (which does not make sense for real-time strategy)?
gena72 is offline  
Reply With Quote
Old 01-11-2012, 07:18 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

It would be per default the oldest bar on the chart and then advance through all bars until it hits your current realtime bar.

If you would like to not calculate anything on historical bars, use Historical to return out of OnBarUpdate() for those bars.

http://www.ninjatrader.com/support/h...historical.htm
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 01-11-2012, 07:21 AM   #7
gena72
Junior Member
 
Join Date: Dec 2011
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
Default

So the strategy will be actually running in two modes. Historical first, and then, real-time. Interesting, I will check this out.

Thank you.
gena72 is offline  
Reply With Quote
Old 01-11-2012, 07:24 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Correct, unless you filter with Historical - it arrives at it's historical strategy position and then trades live.
NinjaTrader_Bertrand 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
Historical Data Load Problem oz-dog Charting 7 02-19-2011 03:15 AM
cannot load historical data crmcwi Connecting 11 06-04-2010 11:23 AM
When does NinjaTrader Load Historical Data AnotherTrader Miscellaneous Support 7 04-13-2010 09:10 AM
wont load historical data davidwm88 Charting 2 06-21-2009 11:54 AM
Can't load historical data Bud_Fox Charting 19 05-18-2009 09:18 AM


All times are GMT -6. The time now is 09:17 PM.