• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Extract minute timestamp for use in strategy

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

    Extract minute timestamp for use in strategy

    I need help with backtesting when trying to acquire the proper BarsSinceNewTradingDay result in a multi-time frame strategy.

    Strategy Specs:
    BarsInProgress == 0: 3 minutes
    BarsInProgress == 1: 6 minutes


    Trading in realtime allows for BarsSinceNewTradingDay to supply a proper result because it updates on each tick. Backtesting is a problem because the BarsSinceNewTradingDay counter only updates "on bar close".

    The bulk of my strategy calculates in BarsInProgress == 0. Since BarsSinceNewTradingDay does not allow it to reference other BarsArray, I have it called in BarsInProgress == 1 to get the result.

    The issue is every other 3 min. bar references the wrong 6 min. BarsSinceNewTradingDay when backtesting. (Calculate.OnBarClose)

    My initial thought is to define which bars need correction and apply a fix for each bar. The basic structure is below. The question is: How do I extract the BarsInProgress == 0 "minute timestamp" to allow for a correction to be applied?

    Code:
    if (BarsInProgress == 1)
    {          
        if (!State.Realtime && Times[0][0] “minute timestamp“ is:  03 || 09 || 15 || 21 || 27 || 33 || 39 || 45 || 51 || 57)
        {
            BarSaved = BarsSinceNewTradingDay + 1;
        }
    }
    Are there better ideas how to solve this problem?

    Thanks in advance!

    #2
    Hello ArmKnuckle,

    To confirm, when you mention BarsSinceNewTradingDay only updates OnBarUpdate in historical, may I confirm that TickReplay is enabled and this value is not returning the correct number of bars since the beginning of the session on the first tick of a new bar?

    Use BarsArray[1].BarsSinceNewTradingDay or BarsArray[0].BarsSinceNewTradingDay depending on which series you want the value from.
    https://ninjatrader.com/support/help.../barsarray.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      Thanks for the quick reply. I haven't tried backtesting with TickReplay. It sounds like it could do the trick!

      One important question though. If I am connected to IQFeed, will a backtest with TickReplay enabled automatically download tick data to use in the calculation? If so, great!

      If not...trouble. I am backtesting 500 stocks daily, and it is not feasible to download tick data for each stock.

      If automatic tick data download isn't available, could we go back to the original question about extracting the "minute timestamp" from Times[0][0]?

      Thanks again!

      Comment


        #4
        Hello ArmKnuckle,

        Tick data is automatically downloaded for TickReplay if the Connection type does support historical tick data.

        Kinetick does supply some historical tick data.
        https://ninjatrader.com/support/foru...958#post597958


        May I confirm that BarsArray[1].BarsSinceNewTradingDay or BarsArray[0].BarsSinceNewTradingDay did not provide you with the information you were looking for?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello Chelsea,

          I am in the process of backtesting with TickReplay enabled. (My backtest duration is 30 days.) I was limited to 8 days of historical tick data when I ran a backtest just after the market closed. I have since learned a full 180 days of data is available after 5 PM EST.

          It is now 8 PM EST, and I can't download anything beyond 8 days. I should have tick data that stretches back 30 days, correct?

          Is there a way to reset/rebuild/force the DB to see that the tick data is missing and complete to the full download of 30 days of historical tick data?

          Thanks!
          Last edited by ArmKnuckle; 08-14-2019, 07:01 PM.

          Comment


            #6
            Hello ArmKnuckle,

            Open a tick chart with the load data based on set to custom range and set the range to cover the period.
            Right-click the chart select reload all historical data.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello Chelsea,

              Thanks for for the response. Will this allow all the historical tick data needed in my 500 stock instrument list to be reloaded? I just want to confirm that “reload all historical data” isn’t just limited to the stock loaded in the chart when choosing the command. Will running a backtest with “Tick Replay” enabled reload all historical data for the hundreds of stocks?
              Last edited by ArmKnuckle; 08-15-2019, 08:04 AM.

              Comment


                #8
                Hello ArmKnuckle,

                Data will be downloaded if its missing up to the current time.

                If some data has been downloaded and there is data missing from before that but data is existing from further before that, the data will need to be reloaded.
                https://ninjatrader.com/support/help...historicaldata

                No, reloading a chart will only reload data for that one instrument.

                You can choose to delete all historical data so this will download automatically.
                https://ninjatrader.com/support/help...HistoricalData
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  What is the fastest way to mass delete the historical data? I have thousands of stocks in my list? Delete folders in Windows Explorer and reset the DB? Clicking one stock at a time is too much.

                  Comment


                    #10
                    Hello ArmKnuckle,

                    Below is a link to the help guide on the Historical Data window and how to delete data.
                    https://ninjatrader.com/support/help...HistoricalData

                    Tools -> Historical Data
                    Right-click Historical -> select Remove
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks. That was sent previously. Can I mass delete historical data all at once? I don't have time to delete over 1,000 stocks one at a time.

                      Comment


                        #12
                        Hello ArmKnuckle,

                        Yes it is possible to delete all historical data at once.

                        Tools -> Historical Data
                        Right-click Historical -> select Remove
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by ct_fx, Today, 05:14 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post ct_fx
                        by ct_fx
                         
                        Started by Beauregard, Today, 04:36 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post Beauregard  
                        Started by fx.practic, Today, 04:34 AM
                        0 responses
                        6 views
                        0 likes
                        Last Post fx.practic  
                        Started by thomaspartyof10, Today, 02:33 AM
                        0 responses
                        9 views
                        0 likes
                        Last Post thomaspartyof10  
                        Started by ArmKnuckle, Today, 01:59 AM
                        0 responses
                        13 views
                        0 likes
                        Last Post ArmKnuckle  
                        Working...
                        X