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

Bars.BarsInSession property?

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

    Bars.BarsInSession property?

    Is there a way to obtain the number of bars in a session (trading day) before calculating it in OnBarUpdate( )? I would need it to simplify declaring and initializing a jagged array.

    Kindly, FREEN

    #2
    Unfortunately there would not be a supported property to query those ahead...you can use Bars.BarsSinceSession on the last of the first session completed to know the value. Alternatively for time based you would know the # of bars provided it's a liquid instrument.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks Bertrand! Yes, I´m aware this:

      if(Bars.LastBarOfSession)
      {
      Print((Bars.BarsSinceSession+1).ToString());
      }

      Sorry to ask without having tried yet, would it be possible to trigger the OnBarUpdate events only at first session, do the Initializing/declaring with collected data from that session, then run the the OnBarUpdate events as usually?
      Last edited by FREEN; 07-20-2012, 07:09 AM.

      Comment


        #4
        You could not re-trigger the Initialize() event then unfortunately - why not try working off a dynamic list that grows with your task?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          "Although this method is called once on the start of an indicator or strategy, there are times that this method is also called (Opening an indicator dialog) when you may not expect it to."

          Q 1: Is it possible to do the Initializing after OnBarUpdate event/-s?:

          OnBarUpdate
          -collect data

          First Session end flag

          Initialize

          OnBarUpdate
          -main code

          Q 2: List.Add during first session? Thanks, I´ll look into if that does the trick.

          Comment


            #6
            FREEN, the event sequence seen is Initialize(), OnStartUp(), OnBarUpdate() - this could not be changed unfortunately.

            Correct you would add to your list as the OnBarUpdate() runs, it would dynamically size as needed (contrary to classic array)

            Create a new List, add elements to it, and loop over its elements with for and foreach.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              So OnBarUpdate can never be called before Initialize and it can only be called once, correct?

              Comment


                #8
                OnBarUpdate() is always called after Initialize() for your script, however Initialize() can be called multiple times...so if you seek a method that's called one time before the first OnBarUpdate(), use OnStartUp().
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by hazylizard, Today, 08:38 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Erick  
                Started by geddyisodin, Today, 05:20 AM
                2 responses
                17 views
                0 likes
                Last Post geddyisodin  
                Started by Max238, Today, 01:28 AM
                5 responses
                45 views
                0 likes
                Last Post Max238
                by Max238
                 
                Started by giulyko00, Yesterday, 12:03 PM
                3 responses
                13 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by habeebft, Today, 07:27 AM
                1 response
                16 views
                0 likes
                Last Post NinjaTrader_ChristopherS  
                Working...
                X