Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to determine if there is never a FirstBarInSession

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

    How to determine if there is never a FirstBarInSession

    I have a simple indicator which writes the bar numbers onto the chart.

    There are already other indicators out there but I wanted to implement an extra piece of functionality - what I'm saying is that the other indicators don't do what I need and also don't suffer my current problem.

    The current problem stems from how I restart the numbering on sessions - the following code snippet comes from the Plot() method, hence the Bars.Get()

    Code:
    if (Bars.Get(x).FirstBarOfSession)
    {
        sessionBar = baseBar;
    }
    else
    {
        sessionBar++;
    }
    and I use 'baseBar' as a user parameter to let me swap between starting numbering on 0 or on 1.

    This is fine until I change the interval to Daily. Then there is no FirstBarOfSession.

    Without writing a big function to check which Period and Interval is in force, is there another way to check whether there is never a FirstBarOfSession = true?

    #2
    Hi adamus, only idea I would have as well is going over the BarsPeriod your code would see, generating bars not with a session concept underlying you would only have to deal with daily and higher.

    Comment


      #3
      OK I see. The other reason why I didn't do a function based on BarsPeriod is because there are others using this indie who use other Bar types of which I have very limited knowledge. I would have to rely on those users to tell me what they expect.

      Comment


        #4
        I have tested Bars.Get(idx).FirstBarOfSession on the plot method, and it always worked for intraday charts. For daily, weekly and monthly bars, there is no first bar of session. All you need to do is to check whether the current chart is an intraday chart or not:

        Code:
        bool existsFirstBarOfSession;
        
        if (Bars.BarsType.IsIntraday)
             existsFirstBarOfSession = true;
        else
             existsFirstBarOfSession = false;

        Comment


          #5
          OK, I'll put that in. It makes sense, being independent of BarType. Thanks v much.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          652 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          577 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X