Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Syncing Yearly,Quarterly,Monthly,Weekly with the start of session & each other?

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

    Syncing Yearly,Quarterly,Monthly,Weekly with the start of session & each other?

    Hello.

    I am wanting to capture the start of the of a Year, Quarter, Month and weekly, and sync this with the start of the session.

    The issue, is that due to timezones, there are times when a NEW trading session starts, but the technical date(due to my timezone) has not rolled over yet.

    An image is attached for the monthly. In this image, you can see how the FIRST triangle shows the first TRADING SESSION that would account for the first day of the NEW month. But my trading session, spans across two calendar days.

    In general, I'd like to be able to sync the Year, Quarterly, Monthly and Weekly starts.

    Capturing the calendar start can be done via:
    Day Of Month: Time[0].Day ... E.g. 1-31
    Year: Time[0].Year ... E.g. 2024
    Day Of Week: (int)Time[0].DayOfWeek ... E.g. 0-6
    Quarter: (Time[0].Month-1)/3+1 ... E.g. 1-4



    And then comparing the current bar, to the previous bar, and waiting for a change will yield the CALENDAR date of change.

    Is there a best practices type of way to accomplish what I'm trying to accomplish.
    Attached Files
    Last edited by forrestang; 06-07-2024, 09:22 AM.

    #2
    Hello forrestang,

    "I am wanting to capture the start of the of a Year, Quarter, Month and weekly, and sync this with the start of the session."

    I'm not quite understanding what you are meaning by "sync this with the start of the session". Do you mean you want to change the session start time to start at midnight?

    "In this image, you can see how the FIRST triangle shows the first TRADING SESSION that would account for the first day of the NEW month. But my trading session, spans across two calendar days"

    When the month changes, you want the bar number of the first bar of the session (that traversed into a new month), is this correct?

    You can use Bars.BarsSinceNewTradingDay to get the first bar of the session.
    Help guide: NinjaScript > Language Reference > Common > Bars > BarsSinceNewTradingDay

    Code:
    if (CurrentBar < 1)
    return;​
    
    if (Time[0].Month != Time[1].Month) // this bar is the first bar of a new month
    {
        Print(string.Format("{0} | Bars.BarsSinceNewTradingDay: {1}, Time[{1}]: {2}", Time[0], Bars.BarsSinceNewTradingDay, Time[Bars.BarsSinceNewTradingDay]));
        Draw.VerticalLine(this, "tag1", Bars.BarsSinceNewTradingDay, Brushes.Green); // draw a vertical line on the first bar of the session.
    }​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I probably didn't explain that well.

      The script you added, will locate the change of date, and go backwards to get the actual first bar of session. I'd like to know on the first bar, if this is a NEW month, even if the month hasn't rolled over yet.

      I may have something workable now, as I'm comparing the bar before the FirstBarOfSession, to the sessionEND date, via use of the sessionIterator.

      This seems to alleviate the issue I was having.

      Thx, I will post if I have further issues.
      Attached Files

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      581 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      338 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X