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

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
      Josh G.NinjaTrader 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()
            Josh G.NinjaTrader 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?


                Josh G.NinjaTrader Customer Service

                Comment


                  #9
                  Hallelujah

                  Hey Josh, thanks. The BarsInProgress was the key.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by TraderBCL, Today, 04:38 AM
                  2 responses
                  14 views
                  0 likes
                  Last Post TraderBCL  
                  Started by martin70, 03-24-2023, 04:58 AM
                  14 responses
                  105 views
                  0 likes
                  Last Post martin70  
                  Started by Radano, 06-10-2021, 01:40 AM
                  19 responses
                  607 views
                  0 likes
                  Last Post Radano
                  by Radano
                   
                  Started by KenneGaray, Today, 03:48 AM
                  0 responses
                  5 views
                  0 likes
                  Last Post KenneGaray  
                  Started by thanajo, 05-04-2021, 02:11 AM
                  4 responses
                  471 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Working...
                  X