Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

get trading hours for Symbol

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

    get trading hours for Symbol

    1) in NT>Tools>Trading Hours, for each symbol (Tools>Instruments), there is assigned TradingHours template. However, when i open a chart for that symbol, and in DataSeries dialog, i choose different TradingHours, how can i programatically (with indicator) access the assigned TradingHours template which is chosen in Tools>TradingHours settings?

    2) in that case, if i have applied different TradingHours for the symbol in DataSeries Dialog, how can i find (with indicator) if current bar is inside Holiday according to it's original TradingHours template? I have started to code something like this, but i think it's not good way or even don't know how to complete it accurately. Any help?

    Code:
                bool isInsideHoliday = false;
                foreach (KeyValuePair<DateTime, string> holiday in TradingHours.Holidays)
                {
                    var target = holiday.Key;
                    if (Time[0] > target && Time[0] < target.AddDays(1) )
                        isInsideHoliday = true;
                }
                foreach (KeyValuePair<DateTime, PartialHoliday> holiday in TradingHours.PartialHolidays)
                {
                    ...
                }
    Last edited by ttodua; 08-05-2020, 08:40 AM.

    #2
    Hello ttodua,

    The instruments master settings can be located by using the MasterInstrument object:

    Code:
    Instrument.MasterInstrument.TradingHours
    That would be what is defined in the Tools -> Instrument manager

    For checking the full holiday days you would need to use a loop and the Time[0] object to reference the bar series time. Your condition could likely just check if the DateTime dates are equal to see if their on the same day. If you see that not working in some holiday situation you could always expand the condition to include that situation.
    Code:
     
     if (Time[0].Date == target.Date)
    For the partial holiday you would need a more complicated condition because that could be only part of a trading session. You could use the partial holiday objects IsLateBegin or IsEarlyEnd properties to further control the logic here.
    You would likely need to compare if the Date is the same date. Then in another inner condition check if the time falls within the range of the partial holiday timeframe. That likely can be found by comparing the constraint begin and end time against TIme[0].

    Code:
    holiday.Value.Constraint.BeginTime 
    holiday.Value.Constraint.EndTime
    I look forward to being of further assistance.

    Comment


      #3
      Jesse, thanks for reply, always pleasure.
      Well, it would be nice if NinjaTrader had some helper method i.e.:

      bool InsideHoliday( TradingHours passed_TH, DateTime passed_DT )
      {
      ....
      return true_false;
      }

      that, to check if user-passed datetime is inside user-passed TradingHours .

      Comment


        #4
        One way to get this information is via the session iterator, if the time between GetTradingDayBeginLocal and GetTradingDayEndLocal is shorter than the average session, it's time for a holiday.

        Comment

        Latest Posts

        Collapse

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