Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Strategy To Access Historical Data
Collapse
X
-
Strategy To Access Historical Data
I have a strategy whose actions depend on the week prior. For the sake of simplicity, the strategy needs last week's high. One way of doing this is to actually let the strategy run and manually storing this value in a variable. This works well, especially when back testing years of data but it isn't ideal because at some point you may lose market connection or have to shutdown NT and reboot the computer or other tasks which will force the strategy to lose what was stored in its memory (ie: last weeks high). So I need a way of either going back to historical data (look at last week tick by tick) and recalculate the data I need OR save these variables in a more permanent way when it's running like an external database. Any ideas would be much appreciated.Last edited by bc24fl; 12-03-2020, 02:07 PM.Tags: None
-
Hello bc24fl, thanks for writing in.
There are a few ways to get this data from the bar series. If you need to capture a specific tick one week ago you would need to identify the bar during the historical data run when the strategy is processing the exact bar you need the price from. Accessing Time[0] will return the time stamp of the bar the strategy is currently processing, so this technique would involve comparing the Time[0] timestamp (Bar times) to the DateTime.Now timestamp (the current PC time), and determining if the currently processing bar is 1 week away from DateTime.Now.
Another way would be to perform an operation on the current Time[0] DateTime and use GetSlotIndexByTime() e.g.
Code:protected override void OnBarUpdate() { if(Bars.IsFirstBarOfSession) { DateTime x = Time[0].AddDays(-7); Print(Close[CurrentBar - (int)Math.Truncate(ChartControl.GetSlotIndexByTime (x))] + " " + Time[CurrentBar - (int)Math.Truncate(ChartControl.GetSlotIndexByTime (x))]); } }
Using external databases to cache the price for later is not something we could support, but it does not have to be too complicated. All you would really need is a .txt file separated by commas and/or newlines (\n)
We have an example of reading and writing to a txt file here:
https://ninjatrader.com/support/help..._propertie.htm
Please let me know if I can provide any further information.Chris L.NinjaTrader Customer Service
-
Interesting. Does the bar I need historical data from have to be on the chart? More specifically when I load the strategy on live do i need to make sure i have last week's info loading in the chart? Also will this option work with IB see chart (https://ninjatrader.com/support/help...provider.htm)?Last edited by bc24fl; 12-03-2020, 06:51 PM.
Comment
-
Hello bc24fl, thanks for your reply.
Yes, the bar will need to exist on the chart for any of these ideas to work. Make sure there is at least 1 weeks worth of data on the chart. It will work with Interactive Brokers as well.
Please let me know if I can assist any further.Chris L.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_ChrisL View PostHello bc24fl, thanks for your reply.
Yes, the bar will need to exist on the chart for any of these ideas to work. Make sure there is at least 1 weeks worth of data on the chart. It will work with Interactive Brokers as well.
Please let me know if I can assist any further.
Comment
-
Hello bc24fl, thanks for your reply.
Interactive Brokers does not supply historical tick data. You can record the incoming live data as tick data by going to Tools>Options>Market Data>enable "Record Realtime Data As Historical".
Also, consider a data-only service like Kinetick or IQFeed that will supply historical tick data.
If you get historical tick data from a third party in the form of a .txt file, that can also be imported into the platform for testing:
Please let me know if I can provide any further information.Chris L.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by LawrenHom, Today, 10:45 PM
|
0 responses
3 views
0 likes
|
Last Post
by LawrenHom
Today, 10:45 PM
|
||
Started by love2code2trade, Yesterday, 01:45 PM
|
4 responses
28 views
0 likes
|
Last Post Today, 10:31 PM | ||
Started by funk10101, Today, 09:43 PM
|
0 responses
7 views
0 likes
|
Last Post
by funk10101
Today, 09:43 PM
|
||
Started by pkefal, 04-11-2024, 07:39 AM
|
11 responses
37 views
0 likes
|
Last Post
by jeronymite
Today, 09:37 PM
|
||
Started by bill2023, Yesterday, 08:51 AM
|
8 responses
44 views
0 likes
|
Last Post
by bill2023
Today, 09:27 PM
|
Comment