Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

FirstBarOfSession - GetNextBeginEnd

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

    FirstBarOfSession - GetNextBeginEnd

    Hi Guys,

    Simple question... When I run the following code on HSI which has 2 sessions per day the print commands execute 4 times per day.

    By my calculations if there are 2 sessions per day then "Bars.FirstBarOfSession" should only execute 2 times. Also, as you will see from the print below, the first two prints are at different times 9:46 (the first bar) then 10:00 (no idea why) then twice at 2:30pm, the Open of the afternoon session.

    N.b. This is not a one off, it does it for the whole series.

    Thoughts???

    protected override void OnBarUpdate()
    {
    // Use the first day of simulation to initialize data
    if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired || CurrentBars[2] < BarsRequired)
    {
    return;
    }
    if (Bars.FirstBarOfSession)
    {
    Print("Current DateTime: " + Time[0].ToString());
    Bars.Session.GetNextBeginEnd(BarsArray[0], 0, out sessionBegin, out sessionEnd);
    Print("Session Start: " + sessionBegin + " Session End: " + sessionEnd);
    }

    // SAMPLE OUTPUT

    Current DateTime: 3/1/2011 9:46:00 AM
    Session Start: 3/1/2011 9:15:00 AM Session End: 3/1/2011 12:00:00 PM
    Current DateTime: 3/1/2011 10:00:00 AM
    Session Start: 3/1/2011 9:15:00 AM Session End: 3/1/2011 12:00:00 PM
    Current DateTime: 3/1/2011 2:30:00 PM
    Session Start: 3/1/2011 1:30:00 PM Session End: 3/1/2011 4:15:00 PM
    Current DateTime: 3/1/2011 2:30:00 PM
    Session Start: 3/1/2011 1:30:00 PM Session End: 3/1/2011 4:15:00 P

    #2
    Aspirant, this would be expected since you do not filter for any BarsInProgress here in your code, thus both objects calling your prints.

    Comment


      #3
      It's interesting, I was actually using a Case statement to control the "BarsInProgress". I have now switched to If statements and the problem has gone away. Very strange...

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      637 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      569 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      571 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X