Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    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 ScottWalsh, 04-16-2024, 04:29 PM
        7 responses
        34 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cls71, Today, 04:45 AM
        0 responses
        3 views
        0 likes
        Last Post cls71
        by cls71
         
        Started by mjairg, 07-20-2023, 11:57 PM
        3 responses
        214 views
        1 like
        Last Post PaulMohn  
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        545 views
        0 likes
        Last Post PaulMohn  
        Started by GLFX005, Today, 03:23 AM
        0 responses
        3 views
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Working...
        X