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 mmenigma, Today, 02:22 PM
                      0 responses
                      1 view
                      0 likes
                      Last Post mmenigma  
                      Started by frankthearm, Today, 09:08 AM
                      9 responses
                      35 views
                      0 likes
                      Last Post NinjaTrader_Clayton  
                      Started by NRITV, Today, 01:15 PM
                      2 responses
                      9 views
                      0 likes
                      Last Post NRITV
                      by NRITV
                       
                      Started by maybeimnotrader, Yesterday, 05:46 PM
                      5 responses
                      26 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by quantismo, Yesterday, 05:13 PM
                      2 responses
                      21 views
                      0 likes
                      Last Post quantismo  
                      Working...
                      X