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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      67 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      36 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      60 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      62 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X