• 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

NT8 Session filtering

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

    NT8 Session filtering

    Hello

    I have trading hours applied to 10 Range chart.
    My custom indicator process every trade by OnMarketData() event.
    The problem is that data still are coming after session ended with CurrentBar = last bar on chart. As you can see my ladder bar collected all the data after end of RTH session. But I need to stop at session end.

    How can I manage this? My obvious wish is not to receive data outside Trading hours.


    #2
    Hello ren37, and thank you for your query.

    In order to detect when the session is over, you will need code such as this at the beginning of OnBarUpdate. I am providing an excerpt from the help guide :

    Originally posted by http://ninjatrader.com/support/helpGuides/nt7/totime.htm
    Code:
    protected override void OnBarUpdate()
    {
    
        // Only trade between 7:45 AM and 1:45 PM
        if (ToTime(Time[0]) >= 74500 && ToTime(Time[0]) <= 134500)
        {
             return;
        }
    
    
        // more code goes here
    
    }
    

    With the bolded integer, change 13 to the hour of the day you would like to change, the 45 to the minute within the hour, and 00 to the seconds within the minute. For example, 4 PM would look like this : 160000 .


    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Do you really think it's a proper solution for Trading hours template like this?

      Code:
      Session 0: Sunday at 2350 to Monday at 630
      Session 1: Monday at 710 to Monday at 2000
      Session 2: Monday at 2350 to Tuesday at 630
      Session 3: Tuesday at 710 to Tuesday at 2000
      Session 4: Tuesday at 2350 to Wednesday at 630
      Session 5: Wednesday at 710 to Wednesday at 2000
      Session 6: Wednesday at 2350 to Thursday at 630
      Session 7: Thursday at 710 to Thursday at 2000
      Session 8: Thursday at 2350 to Friday at 630
      Session 9: Friday at 710 to Friday at 2000
      Why not to filter data serie inside NT core by TH template settings like NT does it on charts? Maybe NT8 has some option for this?

      Comment


        #4
        Hello Ren,

        If you would like, you can access the session's beginning and ending times using Bars.Session.GetNextBeginEnd, documented in the help guide here, https://ninjatrader.com/support/help...xtbeginend.htm .

        I am incorporating this into my code sample.

        Code:
        private DateTime sessionStart;
        private DateTime sessionStop;
        
        protected override void OnBarUpdate()
        {
            // On the start of a new session, get the next begin or end session time
            if (Bars.FirstBarOfSession)
            {
                Bars.Session.GetNextBeginEnd(BarsArray[0], 0, out sessionStart, out sessionStop);
            }
            if (sessionStart == null || sessionStop == null)
            {
                return;
            }
        
             // Only trade between session start and session stop
            if (ToTime(Time[0]) >= ToTime(sessionStart) && ToTime(Time[0]) <= ToTime(sessionStop))
            {
                 return;
            }
        
        
             // more code goes here
        
        }
        
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Your code is for NT7.
          In NT8 there is no method to get session instance or session begin/end time by bar index, only by session index.

          Comment


            #6
            Hello Ren,
            My apologies.

            This is the same code sample modified for NT8.

            http://ninjatrader.com/support/helpG...ssionbegin.htm

            Code:
            private SessionIteratorsessionIterator;
            private DateTime sessionStart;
            private DateTime sessionStop;
            
            protected override void OnStateChange()
            {
                // more code here
                if (State == State.Historical)
                {
                    // more code here
                    sessionIterator = new SessionIterator(Bars);
                }
                // more code here
            }
            
            protected override void OnBarUpdate()
            {
                // On the start of a new session, get the next begin or end session time
                if (Bars.FirstBarOfSession)
                {
                    // use the current bar time to calculate the next session
                    sessionIterator.GetNextSession(Time[0], true);
            
                    sessionStart = 
            sessionIterator.ActualSessionBegin;
                    sessionStop = 
            sessionIterator.ActualSessionEnd;
                 }
                if (sessionStart == null || sessionStop == null)
                {
                    return;
                }
            
                 // Only trade between session start and session stop
                if (ToTime(Time[0]) >= ToTime(sessionStart) && ToTime(Time[0]) <= ToTime(sessionStop))
                {
                     return;
                }
            
            
                 // more code goes here
            
            }
            
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Ty for SessionIterator class.
              I think this code is much simpler

              Code:
                      public override void AddVolume(TradeSide side, MarketDataEventArgs e)
                      {
                          // Check session time
                          if (!indicator.SessionIterator.IsInSession(e.Time, true, true))
                              return;
              Last edited by ren37; 06-04-2016, 04:10 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rickyblah12, Today, 06:19 PM
              0 responses
              2 views
              0 likes
              Last Post rickyblah12  
              Started by ballboy11, Today, 05:22 PM
              0 responses
              2 views
              0 likes
              Last Post ballboy11  
              Started by ballboy11, Today, 04:33 PM
              2 responses
              3 views
              0 likes
              Last Post ballboy11  
              Started by dedouglas, Today, 03:16 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by TradeMyth, Today, 02:45 PM
              3 responses
              19 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X