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

Get # of Sessions

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

    Get # of Sessions

    Hi guys, Is there a way to get the # of sessions that have occurred since a backtest started? My primary series is BetterRenko 4, but I want to test how many days have passed during the backtest for my primary series.

    #2
    Hello elitetradernyc,

    You may manually calculate this by using the Bars.FirstBarOfSession and checking for your series. For example:

    Code:
    int counter = 0;
    if(BarsInProgress == 0 && Bars.FirstBarOfSession)
         counter++;


    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thanks, one other question, I want to get the close of two sessions ago, like PriorDayOHLC().PriorClose[x] but how do you get it to look back two sessions and not just 1?

      Thanks

      Comment


        #4
        Hello elitetradernyc,

        This is something also that would have to be calculated if you want to use the PriorDayOHCL() indicator as well.

        Since you are checking for the start of a session you can save the bar that new session starts on so that you can reference it later inside of the PirorDayOHLC().PriorClose[x] so since you know what bar the session started on you can use the "CurrentBar" minus the variable that has the variable that is storing what bar the session you want to access it from.

        Let me know if you have any questions.
        JCNinjaTrader Customer Service

        Comment


          #5
          Originally posted by elitetradernyc View Post
          Thanks, one other question, I want to get the close of two sessions ago, like PriorDayOHLC().PriorClose[x] but how do you get it to look back two sessions and not just 1?

          Thanks
          You merely need to make sure that your reference bar is the day before.
          Code:
          PriorDayOHLC().PriorClose[GetBar(Time[0].AddDays(-1))]

          Comment


            #6
            Thanks, I was adding an array to store all the previous values and that really slowed down my backtests, perhaps ill try doing it another way.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,607 views
            0 likes
            Last Post aligator  
            Started by jaybedreamin, Today, 05:56 PM
            0 responses
            9 views
            0 likes
            Last Post jaybedreamin  
            Started by DJ888, 04-16-2024, 06:09 PM
            6 responses
            19 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            6 views
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            16 views
            0 likes
            Last Post Javierw.ok  
            Working...
            X