• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Finding Average of Secondary Instrument

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

    Finding Average of Secondary Instrument

    Hi. I'm trying to do something pretty basic I think but I guess my understanding of Series and multiinstrument setups isn't quite where it needs to be.

    I have added some secondary instruments as follows:
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 5);
    AddDataSeries("^VIX", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
    AddDataSeries("ZN 06-18", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
    AddDataSeries("RTY 06-18", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
    }

    All I'm trying to do is OnBarUpdate define a variable equal to the maximum value of my Vix data series over the prior 12 bars. Should be easy I think but not getting what I want so far.

    Thanks!

    #2
    clarification... Seeking Max value

    Hi. My previous header said I was trying to find an Average value, but in fact I'm trying to find the Max as indicated in the text.

    Comment


      #3
      Hello stewarco,
      Thanks for your post.

      You can use HighestBar() to get that value and BarsArray to reference the added data series. The following would be appropriate to use with your State.Configure code.

      Code:
      myHighBar = HighestBar(BarsArray[2],12);
      Help Guide - HighestBar()
      Help Guide - BarsArray

      Let me know if you have any questions
      JoshNinjaTrader Customer Service

      Comment


        #4
        err message

        Thanks Josh. When I declare MyHighBar, what type should it be? Is the code you provided supposed to go in OnStateChange or OnBarUpdate?

        When I put it in OnStateChange I'm getting an Error "OnStateChange" object reference not set to an instance of an object.
        When I put it in OnBarUpdate, I'm getting an Error you are accessing a value that is invalid because it is out of range. I'm confuse by this because the error occurs on bar 20 whereas I'm only looking back 12 periods to find the high bar (the code has other constraints that prevent it from starting sooner than bar 20).

        Comment


          #5
          btw...

          By the way, I see I inadvertently posted this under Ninja7, but I'm actually using Ninja8

          Comment


            #6
            That is going to be a type double variable inside OnBarUpdate().

            Here is the help guide for NT8. There is a better sample here than in the NT7 document.
            Help Guide - HighestBar()
            JoshNinjaTrader Customer Service

            Comment


              #7
              the other question...

              Thanks. Any idea about this?
              When I put it in OnBarUpdate, I'm getting an Error "you are accessing a value that is invalid because it is out of range". I'm confuse by this because the error occurs on bar 20 whereas I'm only looking back 12 periods to find the high bar (the code has other constraints that prevent it from starting sooner than bar 20).

              I get the same Error even if I just try to do Print(Closes[2][0]) to check the value of the series. Is there another step I'm missing aside from AddDataSeries to make sure the bars are updated?

              Thanks

              Comment


                #8
                Are you doing your 'bar check' to make sure there are enough bars?
                Are you checking for the correct BarsInProgress as well?

                https://ninjatrader.com/support/help...nough_bars.htm
                https://ninjatrader.com/support/help...inprogress.htm
                JoshNinjaTrader Customer Service

                Comment


                  #9
                  Hallelujah

                  Hey Josh, thanks. The BarsInProgress was the key.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Shansen, 12-31-2016, 10:51 PM
                  4 responses
                  996 views
                  0 likes
                  Last Post fx.practic  
                  Started by sandman, Today, 05:47 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post sandman
                  by sandman
                   
                  Started by sidviciousX, Yesterday, 07:24 PM
                  2 responses
                  12 views
                  0 likes
                  Last Post sidviciousX  
                  Started by cls71, Today, 04:31 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post cls71
                  by cls71
                   
                  Started by KSTrader, Today, 12:45 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post KSTrader  
                  Working...
                  X