Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8211033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:17:18+00:00 2026-06-07T10:17:18+00:00

I’m having trouble figuring out which tradings session any particular time is in. There

  • 0

I’m having trouble figuring out which tradings session any particular time is in.

There are four possible sessions, show in this picture taken from ForexFactory.com

enter image description here

I have this method that I need to check is currentTime is during the specified trading session.

public bool IsTradingSession(TradingSession tradingSession, DateTime currentTime)
{
    //currentTime is in local time.


    //Regular session is 5PM - next day 5PM, this is the session in the picture.
    //Irregular sessions also occur for example late open (3AM - same day 5PM)  or early close (5PM - next day 11AM)
    DateTime sessionStart = Exchange.ToLocalTime(Exchange.CurrentSessionOpen);
    DateTime sessionEnd = Exchange.ToLocalTime(Exchange.CurrentSessionClose);

    if(tradingSession == TradingSession.Sydney)
        return ....... ? true : false;
    if(tradingSession == TradingSession.Tokyo)
        return ....... ? true : false;        
    if(tradingSession == TradingSession.London)
        return ....... ? true : false;
    if (tradingSession == TradingSession.NewYork)
        return ....... ? true : false;

    return false;
}

Use:

    bool isSydneySession = IsTradingSession(TradingSession.Sydney, CurrentTime);
    bool isTokyoSession = IsTradingSession(TradingSession.Tokyo, CurrentTime);
    bool isLondonSession = IsTradingSession(TradingSession.London, CurrentTime);
    bool isNewYorkSession = IsTradingSession(TradingSession.NewYork, CurrentTime);

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:17:20+00:00Added an answer on June 7, 2026 at 10:17 am

    I’d suggest writing a simple function for each trading session, which takes a DateTime and returns a bool indicating if it’s open at that time.

    var sydneyOpen = new TimeSpan(17, 0, 0);
    var sydneyClose = new TimeSpan(2, 0, 0);
    Func<DateTime, bool> isOpenInSydney = d => 
        (d.TimeOfDay > sydneyOpen || d.TimeOfDay < sydneyClose);
    
    // same for other markets, write a function to check against two times
    

    Then place these into a Dictionary<TradingSession, Func> like this for generic retrieval…

    var marketHours = new Dictionary<TradingSession, Func<DateTime, bool>>();
    marketHours.Add(TradingSession.Sydney, isOpenInSydney);
    // add other markets...
    

    And then your existing method simply selects the appropriate function for the given TradingSession and applies it

    public bool IsTradingSession(TradingSession tradingSession, DateTime currentTime)
    {
        var functionForSession = marketHours[tradingSession];
        return functionForSession(currentTime);
    }
    

    I don’t believe you need UTC time here as long as your application only runs in a single timezone, but daylight savings might cause problems.


    A nice way to account for the problem of trading sessions which cover two days, as opposed to just one day, is to write a helper that precisely considers whether it’s a ‘cross-day’ trading session and applies a different rule for you:

    private bool IsBetween(DateTime now, TimeSpan open, TimeSpan close)
    {
        var nowTime = now.TimeOfDay;
        return (open < close
            // if open is before close, then now must be between them
            ? (nowTime > open && nowTime < close)
            // otherwise now must be *either* after open or before close
            : (nowTime > open || nowTime < close));
    }
    

    and then

    var sydneyOpen = new TimeSpan(17, 0, 0);
    var sydneyClose = new TimeSpan(2, 0, 0);
    Func<DateTime, bool> isOpenInSydney = d => IsBetween(d, sydneyOpen, sydneyClose);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a text area in my form which accepts all possible characters from
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.