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

existing indicator?

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

    existing indicator?

    Hello. I'm wondering if you guys are aware of any existing indicators I can use for calculating market beta for an instrument? even if there are only subcomponents available, eg. variance or covariance that would be a start. if not I can build them relatively easily but figure i'd just check first.

    thanks

    #2
    Hello stewarco,

    Thanks for your post.

    There does appear to be an existing NinjaTrader 7 indicator that accomplishes this task. The NinjaTrader 8 Code Breaking Changes page of the help guide could be referenced when converting this indicator to NinjaTrader 8.

    NT7 Beta indicator - https://ninjatrader.com/support/foru...tid=-1&lpage=1

    Code Breaking Changes - https://ninjatrader.com/support/help...ng_changes.htm

    Please let us know if there is anything else we can do to help.
    JimNinjaTrader Customer Service

    Comment


      #3
      a few questions

      Hi. So I decided to go ahead and build my own indicator.
      1) Does this indicator get updated on every bar update, regardless of whether I call it or not?
      2) Are the values then forthwith associated with that same bar? eg. what is now Indicator[0] becomes Indicator[10] 10 bars later?
      3) If I have created a series within that indicator, are those values also linked to a specific bar going forward, or do I need to redefine the series every time I call it?
      4) In the body of the indicator, where do I actually specifiy the value that is being returned? Eg., my indicator is called Covariance, and I have a variable covariance that is equal to the value I want, but it's unclear to me how I associate that with the actual value that is returned from my indicator when I call it.
      5) Is there a place in my strategy code where I need to let the strategy know that a given indicator is going to be used prior to me calling it?

      Thanks

      Comment


        #4
        Hello stewarco,

        Thanks for your additional questions.

        1) Does this indicator get updated on every bar update, regardless of whether I call it or not?
        If you add an instance of an indicator to a strategy or other hosting NinjaScript (as seen when adding indicators using the Strategy Builder) they will stay updated.

        2) Are the values then forthwith associated with that same bar? eg. what is now Indicator[0] becomes Indicator[10] 10 bars later?
        Yes. The Series<double> output of the indicator will be synchronized to the Series that is used for the indicator input.

        3) If I have created a series within that indicator, are those values also linked to a specific bar going forward, or do I need to redefine the series every time I call it?
        Series objects should be created in State.DataLoaded and they will be synchronized to the primary data series the NinjaScript is applied to. The Series would not need to be redefined.

        4) In the body of the indicator, where do I actually specifiy the value that is being returned? Eg., my indicator is called Covariance, and I have a variable covariance that is equal to the value I want, but it's unclear to me how I associate that with the actual value that is returned from my indicator when I call it.
        Indicators add plots and then assign the plot values with Value, or Values for multi plot indicators.

        5) Is there a place in my strategy code where I need to let the strategy know that a given indicator is going to be used prior to me calling it?
        You can add the indicator with AddChartIndicator() in State.DataLoaded so the indicator gets applied to a chart. Otherwise, you may instantiate the indicator in State.DataLoaded and it will not be added to a chart.

        I would recommend using the Strategy Builder to get more acquainted with syntax for adding indicators to strategies and using strategies all together. Our open source indicators can also be referenced for how an indicator plots data.

        Documentation items that can be referenced for further reading as well as a link to the Strategy Builder 301 tutorial are linked below.

        Strategy Builder 301 - https://ninjatrader.com/Webinar/Strategy-Builder-301

        Series<t> - https://ninjatrader.com/support/help...us/seriest.htm
        AddPlot() - https://ninjatrader.com/support/help...us/addplot.htm
        Value - https://ninjatrader.com/support/help...n-us/value.htm
        Values - https://ninjatrader.com/support/help...-us/values.htm

        We look forward to being of any further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          one more thing

          ok. two more questions:

          1) so I see that you say Indicator return Values. does that mean if the quantity I ultimately want to return is called x, then at some point in the indicator I would make an assignment statement Value = x?

          2) A related question, I guess: since I don't really need to show these on a chart, but instead am just looking for a function I can use to in a variety of strategies to return the value of a relatively complex calculation, is there a better way for me to accomplish this (as opposed to simply copying the block of code and inserting it in each strategy)?
          Thanks

          Comment


            #6
            Hello stewarco,

            Happy to answer.

            1) so I see that you say Indicator return Values. does that mean if the quantity I ultimately want to return is called x, then at some point in the indicator I would make an assignment statement Value = x?
            The assignment would be Value[0] = x; after adding the plot in State.SetDefaults with AddPlot(). The AddPlot() document can also has some examples that can be referenced for Plot creation and assignment.

            2) A related question, I guess: since I don't really need to show these on a chart, but instead am just looking for a function I can use to in a variety of strategies to return the value of a relatively complex calculation, is there a better way for me to accomplish this (as opposed to simply copying the block of code and inserting it in each strategy)?
            Adding the plot and creating an indicator will allow the indicator to be used separately throughout the platform which will have its benefits. The indicator will only be added to the chart from a strategy if you add the indicator with AddChartIndicator(). If performance is a major concern of yours, you could consider unrolling any calculations that would be done in the indicator so that you ultimately perform less operations. I generally would not expect most indicators to cause that great of a performance hit, though.

            AddChartIndicator() - https://ninjatrader.com/support/help...tindicator.htm

            If there is anything else that you come across that isn't clear, please don't hesitate to ask.
            JimNinjaTrader Customer Service

            Comment


              #7
              hi

              ok thanks. So it sounds like the AddPlot methodology is the way to go regardless of whether I ever plan to look at it on a chart or not.
              I haven't done that yet, and currently I have strange problem that while the "main code"might be on bar 100, as soon as i'm within the indicator code it is telling me I'm on bar number (-1) so I keep getting out of range errors. Any idea why this would happen? I'll try doing the AddPlot for now and see what happens.

              Comment


                #8
                Hello stewarco,

                Debugging steps will need to be taken to better understand the error received and how it should be corrected. I've included some resources on debugging tips and some referencing errors in this post.

                It may prove useful to first create the indicator framework for adding a plot and then assigning the plot's Value with Close[0] before proceeding with your port. This way you can approach the conversion of the indicator separately from the creating the underlying framework.

                Debugging tips - https://ninjatrader.com/support/help...script_cod.htm
                Index out of range errors (specifically for making sure there are enough bars for your calculations.) - https://ninjatrader.com/support/help...nough_bars.htm

                As a more direct tip, adding prints throughout the code will point to where you see the error and it should then be possible to understand how to fix it.

                Please let us know if you have any questions on these materials.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by timmbbo, Today, 08:59 AM
                1 response
                2 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by KennyK, 05-29-2017, 02:02 AM
                2 responses
                1,279 views
                0 likes
                Last Post marcus2300  
                Started by fernandobr, Today, 09:11 AM
                0 responses
                0 views
                0 likes
                Last Post fernandobr  
                Started by itrader46, Today, 09:04 AM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by bmartz, 03-12-2024, 06:12 AM
                5 responses
                33 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Working...
                X