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

BarsType Tick Based SessionIterator

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

    BarsType Tick Based SessionIterator

    Hi

    I have some problem with barstype development.
    Here is the code.

    Code:
    protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask) {
        if (SessionIterator == null)
            SessionIterator = new SessionIterator(bars);
    
        bool isNewSession = SessionIterator.IsNewSession(time, isBar);
    
        if (isNewSession)
            SessionIterator.GetNextSession(time, isBar);
    
        if(isNewSession)
        {
            Print("New session "+time);
        }
    }
    So this script should print "New Session" on the start of the session.
    The issue is when I'm running it on CL 12-18 90 Days, I have duplicate records in the Output with the same date.


    I have attached output screenshot and cs file with code.
    Last edited by NinjaTrader_ChelseaB; 11-08-2018, 11:25 AM. Reason: Customer requested script be removed

    #2
    Hello blekdzhon,

    In this case, it looks like this would be expected in contrast to what you have provided. The sample you are testing does not contain enough logic to accurately print the new session for futures instruments. You will see what you have pictured when crossing rollover dates specifically.

    For more suggestions on how to accomplish what you are trying to do, I would suggest looking at one of the existing bars types that use the session information such as the tick bars as that is one of the more simple types.

    It is not apparent what you want to do based on the sample other than print the change of session, have you at this point constructed a more complete BarsType and run into a problem which this question stems from? If not and this was simply an observation, you would need to further design the bars type similar to the existing types to control the session accurately. Otherwise, can you provide more details surrounding the problem you are seeing?


    I look forward to being of further assistance.
    Last edited by NinjaTrader_Jesse; 11-07-2018, 10:39 AM. Reason: updated information
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse

      I'm creating barstype like renko, and I need to calculate ATR indicator in it. That's why I need to know when new session starts.
      The barstype is based on ticks. Also the example I sent you is based on tick.
      I checked Renko barstype and it has the same behavior.

      Comment


        #4
        Hello blekdzhon,

        Yes if you are just adding a print like you have shown, that would be the expected outcome for the reasons mentioned in the prior post. This relates specifically to futures instruments and the merge settings used.

        Have you constructed logic at this point similar to how the existing bars types are formed which have more complex conditions to check for the new session? There is also handling for the bar count which is needed. If you note in the existing types, the bool isNewSession is not directly used for logic but is used in combination with other logic.

        If the print is expanded on, you can further identify the difference you are seeing:
        Code:
        if (isNewSession)
        {
            DateTime oldSessionEnd = SessionIterator.ActualSessionEnd;
            SessionIterator.GetNextSession(time, isBar);
            Print("time: " + time.ToString() + " new ActualSessionEnd: " + SessionIterator.ActualSessionEnd + " old ActualSessionEnd: " + oldSessionEnd + " Instrument: " + bars.Instrument.FullName + " Bars.Count: " + bars.Count);
        }
        We would get the following prints:

        time: 10/14/2018 4:00:00 PM new ActualSessionEnd: 10/15/2018 3:00:00 PM old ActualSessionEnd: 10/12/2018 3:00:00 PM Instrument: CL 11-18 Bars.Count: 9686
        time: 10/15/2018 4:00:00 PM new ActualSessionEnd: 10/16/2018 3:00:00 PM old ActualSessionEnd: 10/15/2018 3:00:00 PM Instrument: CL 11-18 Bars.Count: 10161
        time: 10/16/2018 4:00:00 PM new ActualSessionEnd: 10/17/2018 3:00:00 PM old ActualSessionEnd: 10/16/2018 3:00:00 PM Instrument: CL 11-18 Bars.Count: 10593
        time: 10/15/2018 4:00:00 PM new ActualSessionEnd: 10/16/2018 3:00:00 PM old ActualSessionEnd: 10/9/2018 3:00:00 PM Instrument: CL 12-18 Bars.Count: 0
        time: 10/16/2018 4:00:00 PM new ActualSessionEnd: 10/17/2018 3:00:00 PM old ActualSessionEnd: 10/16/2018 3:00:00 PM Instrument: CL 12-18 Bars.Count: 120
        time: 10/17/2018 4:00:00 PM new ActualSessionEnd: 10/18/2018 3:00:00 PM old ActualSessionEnd: 10/17/2018 3:00:00 PM Instrument: CL 12-18 Bars.Count: 343
        The contract has changed between this date range which causes the effect you have highlighted with your print. Using logic would be the way to move past that similar to how the existing type work and use logic.

        If you take the existing renko and add the print later down the line in its logic, you can see unique days. There is a condition in the script:
        Code:
        if (bars.Count == 0 || bars.IsResetOnNewTradingDay && isNewSession)
        {
        and then inside of this condition is another session check which could be expanded with a print:

        Code:
        isNewSession = SessionIterator.IsNewSession(time, isBar);
        if (isNewSession)
        {
            SessionIterator.GetNextSession(time, isBar);
            Print("new session bar " + time);
        }
        Which outputs the following prints for the same period:

        new session bar 10/14/2018 4:00:00 PM
        new session bar 10/15/2018 4:00:00 PM
        new session bar 10/16/2018 4:00:00 PM
        new session bar 10/17/2018 4:00:00 PM
        new session bar 10/18/2018 4:00:00 PM
        new session bar 10/21/2018 4:00:00 PM
        new session bar 10/22/2018 4:00:00 PM
        new session bar 10/23/2018 4:00:00 PM

        Please let me know if I may be of additional assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Jesse, can you explain how this logic works?

          Code:
          if (SessionIterator == null)
             SessionIterator = new SessionIterator(bars);
          
          bool isNewSession = SessionIterator.IsNewSession(time, isBar);
          if (isNewSession)
             SessionIterator.GetNextSession(time, isBar);
          
          if (bars.Count == 0 || bars.IsResetOnNewTradingDay && isNewSession)
          {
          
          isNewSession = SessionIterator.IsNewSession(time, isBar);
          if (isNewSession)
          {
              SessionIterator.GetNextSession(time, isBar);
              Print("new session bar " + time);
          }
          }
          I see calculating of the new session at the start of the new session, don't see any point in it.

          And I checked Renko bar exactly as in your code, it still prints duplicates.

          Comment


            #6
            Hello blekdzhon,

            A client has written in and stated that they are your customer and that this bar type is being built for them.

            They have requested that this conversation not be on the forums.

            I'd like you to send an email to platformsupport [at] ninjatrader [dot] com so that we may confirm they are your customer. If so, we'll continue assisting through email.
            Please include a link to this forum thread with your email.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by wzgy0920, 04-20-2024, 06:09 PM
            2 responses
            27 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, 02-22-2024, 01:11 AM
            5 responses
            32 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, 04-23-2024, 09:53 PM
            2 responses
            49 views
            0 likes
            Last Post wzgy0920  
            Started by Kensonprib, 04-28-2021, 10:11 AM
            5 responses
            193 views
            0 likes
            Last Post Hasadafa  
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,235 views
            0 likes
            Last Post xiinteractive  
            Working...
            X