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!
See more
See less

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 && [COLOR=#FF0000][B]Times[0][0] “minute timestamp“ is:  03 || 09 || 15 || 21 || 27 || 33 || 39 || 45 || 51 || 57[/B][/COLOR])
        {
            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.
    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.



        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.


                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.

                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.


                    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 ScottWalsh, 04-16-2024, 04:29 PM
                        7 responses
                        34 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by cls71, Today, 04:45 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post cls71
                        by cls71
                         
                        Started by mjairg, 07-20-2023, 11:57 PM
                        3 responses
                        214 views
                        1 like
                        Last Post PaulMohn  
                        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                        4 responses
                        547 views
                        0 likes
                        Last Post PaulMohn  
                        Started by GLFX005, Today, 03:23 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post GLFX005
                        by GLFX005
                         
                        Working...
                        X