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

Multi-instrument multi-timeframe strategy

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

    Multi-instrument multi-timeframe strategy

    I'm looking to determine previous day close price for let say ZC and ES on the first minute bar of the current day. As trading hours are different i'm struggling to figure out that. There is IsFirstBarOfSession yet how this will not work in my situation as session for 2 instruments are different. Any suggestions or reference will be appreciated.

    #2
    Hello PageNotFound404,

    BarsArray[1].IsFirstBarOfSession


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Appreciate.

      Comment


        #4
        Hi,
        After future try/research i still have question:

        Using this as example i did add

        if (BarsArray[1].IsFirstBarOfSession)...

        AddDataSeries("FDAX 03-23",BarsPeriodType.Minute, 1); and get result:
        Calculating trading day for 11/10/2021 9:31:00 AM
        The Current Trading Day 11/10/2021 starts at 11/10/2021 9:30:00 AM and ends at 11/10/2021 5:00:00 PM​

        Then i change the code
        AddDataSeries("ES 03-23",BarsPeriodType.Minute, 1); and get result:
        Calculating trading day for 11/10/2021 9:31:00 AM
        The Current Trading Day 11/10/2021 starts at 11/10/2021 9:30:00 AM and ends at 11/10/2021 5:00:00 PM

        Or w/e i try give me the same result. Yes, i'm using Trading hours "CME US Index Futures RTH"
        As i understand, that may not be accurate, ES and FDAX do have different trading hours.
        So my question is how i can create conditions, calculate time, or determine last bar of the session for the given instrument with ultimate goal trade only within trading hours and do not hold position overnight, or again, another way to pose question have in-force only intraday margin.
        --PNF.​

        Comment


          #5
          Hello PNF,

          The hours data loads for a data series is controlled by the Trading Hours template for that specific series.

          By default the TradingHours of the primary will be used for any additional series added with AddDataSeries(). It is possible to specify the TradingHours with the overload signatures that have a string tradingHoursName parameter. However, when doing so, data will only be processed in OnBarUpdate() when all series in are in session.

          From the help guide:
          "If your NinjaScript object is using AddDataSeries() allowing to specify a tradingHoursName, please keep in mind that: An indicator / strategy with multiple DataSeries of the same instrument will only process realtime OnBarUpdate() calls when a tick occurs in session of the trading hour template of all added series. Any ticks not processed will be queued and processed as a tick comes in for all subsequent DataSeries."
          https://ninjatrader.com/support/help...dataseries.htm

          As you are not specifying the tradingHoursName, you are loading the FDAX 03-23 with the 'CME US Index Futures RTH" trading hours applied.
          Code:
          else if (State == State.DataLoaded)
          {
              if (BarsArray.Count > 1)
                 Print(string.Format("BarsArray[0]: {1}, BarsArray[1]: {1}", BarsArray[0].TradingHours, BarsArray[1].TradingHours));
          }

          The FDAX is on the Eurex exchange using the 'Eurex Equity Index Futures' TradingHours template with a different set of hours.


          Calculating the sessionEnd time or sessionBegin time is typically done with SessionIterator.
          https://ninjatrader.com/support/help...oniterator.htm

          Below is a link to an example that uses the sessionEnd time.
          https://ninjatrader.com/support/foru...ples#post93881

          This accounts for holidays defined in the TradingHours as well.


          Outside of adding a series and using the sessionIterator you can loop through the MasterInstrument.TradingHours.Sessions. But this would not account for holidays and you would need to calculate holidays with further custom logic.
          https://ninjatrader.com/support/help...s_sessions.htm
          https://ninjatrader.com/support/help...8/holidays.htm
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thank you.
            -PNF.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by elirion, Today, 01:36 AM
            0 responses
            1 view
            0 likes
            Last Post elirion
            by elirion
             
            Started by gentlebenthebear, Today, 01:30 AM
            0 responses
            2 views
            0 likes
            Last Post gentlebenthebear  
            Started by samish18, Yesterday, 08:31 AM
            2 responses
            9 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by Mestor, 03-10-2023, 01:50 AM
            16 responses
            389 views
            0 likes
            Last Post z.franck  
            Started by rtwave, 04-12-2024, 09:30 AM
            4 responses
            31 views
            0 likes
            Last Post rtwave
            by rtwave
             
            Working...
            X