Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy To Access Historical Data

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    #2
    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))]);
        }
    }
    Another way to get a literal weekly price would be to add a weekly series using AddDataSeries, then access Closes[1][1] when the secondary series has at least 1 bar processed.

    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

    Comment


      #3
      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


        #4
        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


          #5
          Originally posted by NinjaTrader_ChrisL View Post
          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.
          The reason I asked about Interactive Brokers is because in that data page all historical tick data is set to no. What if I need to get tick data for last week? Or does the tick data still exist because last week is physically on the chart and therefore not considered historical?

          Comment


            #6
            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:

            https://ninjatrader.com/support/help...?importing.htm

            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 dorotwart, Today, 11:43 PM
            0 responses
            2 views
            0 likes
            Last Post dorotwart  
            Started by MatthewLesko, Today, 11:13 PM
            0 responses
            3 views
            0 likes
            Last Post MatthewLesko  
            Started by Lance El Camino, Today, 04:14 PM
            1 response
            13 views
            0 likes
            Last Post s.kinra
            by s.kinra
             
            Started by jtrading82, Today, 04:56 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_ShawnB  
            Started by dmking, Today, 06:00 PM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_EricB  
            Working...
            X