Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest start date from Onstartup

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

    Backtest start date from Onstartup

    Hi,

    My strategy's initial state depends on which date it starts on, so it needs to know what that date is before trading. How can I get the simulation start date before the simulation starts (from oninitialize or on startup)?

    #2
    benoirat, I would just look into Time[0].Date accessed from OnStartUp(), that's basically CurrentBar == 0 then.

    Comment


      #3
      The problem is Time does not seem to be initiated in onstartup.

      Code:
      DateTime startDate = Time[0];
      
      ==> error:
      Bar index needs to be greater/equal 0

      Comment


        #4
        Cannot reproduce here, which BarsRequired do you use for your script?

        Comment


          #5
          Indeed I had set 0. With 1 it works fine.

          Thanks a lot.

          Comment


            #6
            Ok, great.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, Yesterday, 09:41 PM
            1 response
            20 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, Today, 02:41 AM
            0 responses
            7 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, Yesterday, 11:44 PM
            0 responses
            18 views
            0 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            35 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            33 views
            0 likes
            Last Post CarlTrading  
            Working...
            X