Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is it possible to set "Session begins (local time)" from code?

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

    Is it possible to set "Session begins (local time)" from code?

    Is it possible to set "Session begins (local time)" from code?

    Whenever I close and reopen my Ninja Trader application then attempt to do a backtest on the e-mini S&P, the "Session begins (local time)" and "Session ends (local time)" values in the backtest properties DialogBox popup get set back to midnight.

    I would like to do it in the code so that it won't keep getting reset whever I close and open Ninja Trader.

    If this is not possible from code, can I set it somewhere in the Ninja Trader User Interface?

    #2
    Hi ChiTrader2000,

    No, this cannot be set from your NinjaScript code.

    But you can save your backtest results and then open then from the Strategy Analyzer when you work on them again, this will save the settings for the session.

    Maybe more conveniently, you can add a time filter directly to your strategy and then let the code run on the normal 24 hrs session chart...please see this reference sample - http://www.ninjatrader-support2.com/...ead.php?t=3226

    Comment


      #3
      sorry to re-vive an old thread.

      but using Session Begin/End limits the data that you'll send to your indicators.

      whereas just putting times and dates conditions in the onBarUpdate method will just limit orders.
      The results will therefore be different.

      anyother way of limiting Session Begin/End by code knowing that i only want that data in the indicators i call from my code ?
      Should i create a DataSeries that i Set from within a time/date condition and call the indicators with that ? (And off course not synchronize the DS with the 'this' object or there'll be loads of NULL values in the DS and my indicator will go bonkers)

      Comment


        #4
        If you have an all encompassing time filter it will prevent any processing while outside of that time frame. This will have the same effect of changing session bars/end time of the chart. Not sure exactly what you are hoping for.

        Code:
        OnBarUpdate()
        {
             if (time filter)
             {
                  // indicator logic;
             }
        }
        All code outside of the filter will be processed on every single OnBarUpdate(). Any code inside the filter will only process when within the filter range.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I'm talking about the usage of an indicator in a strategy

          Two cases :

          1/ setting session begin = 0900 && session end = 1800
          Code:
          OnBarUpdate()
          {
               
                    if(SMA(Close,5)[0] > 900) EnterLong();
          
          
              
          }
          @9am
          the SMA will use data from 1800 1759 1758 ...

          2/ not putting a session begin end, and putting a "time filter"
          Code:
          OnBarUpdate()
          {
               if (time filter)
               {
                    if(SMA(Close,5)[0] > 900) EnterLong();
          
          
               }
          }
          @9am
          Here the SMA will use data from 0859 0858 0857 ....


          So the result is clearly not the same ...

          Comment


            #6
            Right. So which one do you want? Those are the two routes you can take. Programmatically setting session begin/end times is not supported.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            558 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X