Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting Period Type in Initialize()

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

    Getting Period Type in Initialize()

    Hello,

    I am trying to Add() a second Bars object to the BarsArray in the Initialize() method per instructions in the help file. (Mulit-timeframe Strategy.) I want it to have the same PeriodType as the primary Bars object, but use a custom user-parameter for the actual period. So, like primary = 1500 tick, secondary = 4500 tick.

    BarsArray[0].BarsType.PeriodType seems to provide the right value, but I can't access it from the Initialize() method because NT doesn't allow it (for good reason).

    What is the right way to access this built-in user parameter for the primary Bars object from within the Initialize() method?

    Thanks.

    Scott
    sh_daggett
    NinjaTrader Ecosystem Vendor - NinjaLaunchpad

    #2
    Hello,

    There is a method used in some code that may work for you.



    This is to calculate a spread between two instruments on the same time frame. You may want to specifically look at the Initalize() method to see how they do it.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      You know, I just really love you guys! You are sooooo FAST!

      Thanks a million.

      BarsPeriod.Id

      I never would have guessed.
      sh_daggett
      NinjaTrader Ecosystem Vendor - NinjaLaunchpad

      Comment


        #4
        dagget,

        No problem, we are here to help, thanks for the kind words.

        Yes, one thing to note there though is the Try/Catch block. It was put there for a reason as sometimes you could get an error when trying to access that in that initialize method.

        You could also try using OnStartUp() instead of Initialize() if you run into issues as its called once before the first OnBarUpdate() and more objects/methods are accessible then.

        Adam P.NinjaTrader Customer Service

        Comment


          #5
          So are you saying that using the OnStartUp() method to Add() the second Bars object is kosher in a Strategy (no chart) and in an Indicator?

          Just double checking, because I kind of like that idea instead of using Initialize().

          Thanks.
          sh_daggett
          NinjaTrader Ecosystem Vendor - NinjaLaunchpad

          Comment


            #6
            scott,

            Actually, I am not sure there as I overlooked the Add() method part. It might work but I haven't tried it. I was just thinking about accessing BarsPeriod.Id as you could probably do this in the OnStartup method without the try/catch block.

            I've had to use OnStartUp before here as Initialize() wouldn't work for me, as an example : http://www.ninjatrader.com/support/f...d=4&linkid=535

            I would suggest probably sticking to the Initialize() method as Add() is usually part of that.
            Adam P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, Yesterday, 10:06 AM
            0 responses
            17 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            16 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            14 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            9 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            38 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X