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

Accessing BarsArray[0].Period.Value inside Initialize()

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

    Accessing BarsArray[0].Period.Value inside Initialize()

    Don't know if this is pilot error on my part or not.... but I added the following line to my Initialize() method.

    int myPeriod = BarsArray[0].Period.Value;

    also tried:

    int myPeriod = Bars.Period.Value;

    with the following results.


    1) Code compiled cleanly
    2) Click "Backtest" in StrategyAnalyzer.
    3) Backtest dialog box comes up but has no parameters (it is completely blank!)
    4) Clicking on OK
    generates a System.NullReferenceException

    I'm trying to create a larger timeframe view that is a multiple of the current period in a multibar strategy. So I need the Period of the base chart in order to cumpute the longer timeframe.

    Thanks,

    Jim

    #2
    imported post

    Follow up to previous post. I am able to access Bars and BarsArray inside OnBarUpdate() successfully. But by then it is too late to Add() additional chart views.

    Chicken and egg problem?

    Comment


      #3
      imported post

      You neither should access Bars nor BarsArray in Initialize method. Please try BarPeriods[0].

      Comment


        #4
        imported post

        OK, I tried

        myBarPeriod = BarPeriods[0].Period.Value;

        and received the following during compilation

        "The name 'BarPeriods' does not exist in the current context"

        no go....

        I've hard coded the view sizes for now, so is not a big issue. It just seems like I *should* be able to find out the size and type of the primary chart while Initializing.

        One more question if I may, should it be OK to store a reference to BarsArray in a class member in Initialize() or should I wait until the first OnBarUpdate()?

        Thank you

        Jim

        Comment


          #5
          imported post

          Dierk will respond to this one upon his return, he is out for a few days.
          RayNinjaTrader Customer Service

          Comment


            #6
            imported post

            Is was referring to strategies not indicators. Code below is not supported for indicators.

            Comment


              #7
              imported post

              But..... This is a strategy

              Jim

              Comment


                #8
                imported post

                Please try:
                Code:
                BarsPeriods[0].Value

                Comment


                  #9
                  imported post

                  That worked!

                  Processed 314213 bars in 00:00:41.0781250

                  So... feeling empowered I also tried

                  myBarType = BarsPeriods[
                  0].Type;

                  which did not :XBut thank you for the first one.

                  Jim

                  Comment


                    #10
                    imported post

                    Please try
                    Code:
                    BarsPeriods[0].Id

                    Comment


                      #11
                      imported post

                      That worked also! Way Cool!

                      Processed 314213 bars in 00:00:38.9062500
                      Thank You!

                      Jim

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Aviram Y, Today, 05:29 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post Aviram Y  
                      Started by quantismo, 04-17-2024, 05:13 PM
                      3 responses
                      25 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      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
                      6 views
                      0 likes
                      Last Post cls71
                      by cls71
                       
                      Started by mjairg, 07-20-2023, 11:57 PM
                      3 responses
                      216 views
                      1 like
                      Last Post PaulMohn  
                      Working...
                      X