Announcement

Collapse
No announcement yet.

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.

    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?

        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)

            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().

                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