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

Avoiding redundant call to indicator?

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

    Avoiding redundant call to indicator?

    Lets say I have 5 different indicators on a chart.

    Next, I have 1 master indicator that needs to use the calculated output of each of these 5 indicators to come to it's own calculated output value.

    Is there a way to avoid having these 5 indicators process twice per bar (once for the instance that is running in the chart and once for the instance that is used in the master indicator)?

    In other words, from a programmers point of view, I would like to code the logical equivalent of a Singleton to handle certain calculations and then reuse the singletons output in multiple places.

    Are there any coding recommendations or samples of a Singleton pattern used in the Ninja environment?

    Thanks,
    Gary

    #2
    Hi Gary, this is all done already internally by NinjaTrader.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      It does not appear to be so

      Bertrand,

      Hmmm. I see the OnBarUpdate called once for the instance in the chart and once for the instance referred to by the 2nd indicator.

      To show you what I mean, I coded 2 indicators, GInd1 and GInd2. Gind1 has a print to the console in it. Gind2 calls GInd1. If you put both of them on a chart with your console open you will see that GInd1 prints it's output twice,

      Then I thought Ninja may be using the parameter value somehow to uniquely identify each instance so I made the parameter values the same but GInd1.OnBarUpdate still executes twice.

      Can you see anything wrong with the way GInd2 calls GInd1?

      Gary
      Attached Files

      Comment


        #4
        Hi Gary, thanks this is expected since you call the OnBarUpdate() twice.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          How to fix it?

          Bertrand,

          You have pinpointed the reason for my question! However, this is the only way I know of to have one indicator call another. I see this coding practice in other indicators all the time.
          Is there a better way to make the call?
          Maybe there is something subtle in the way the called indicator is coded that makes it different (like using the line update(); in the method?)?

          The sample I provided shows the idea of what I am trying to accomplish.
          If it is not the right way to call another indicator that is on the chart (and avoid a redundant call) or if there is more code required in GInd1, then can you point out how to correct GInd1 or the call in GInd2? Perhaps there is a page of documentation somewhere that explains this?


          Thanks,
          Gary

          Comment


            #6
            Gary,

            If you add the indicator to the chart for sure it will run. You call the indicator from another indicator it will run. It is still the same instance, but it will run when told to. If you wish for different behavior you could try rolling the two into one indicator.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Back to original question

              Josh,

              That is the behavior I would expect. My original question was asking if there is a way to optimize this. Bertrand's first response could be interpreted to imply that Ninja had internally optimized it.
              If that is not true, that is fine.

              However, that lead to the second part of my original question: What about using the Singleton coding pattern within the Ninja Indicator environment? Would a class created as a single static instance be accessible between two different indicators? Do you have any examples of this or perhaps some recommended coding standards regarding this?

              I understand that I could re-code the outer indicator (GInd2) to have the same logic as the called indicator (GInd1) but if that calculation is intensive it would be nice to not repeat it every bar.

              -Gary

              Comment


                #8
                Gary,

                What Bertrand meant was that NT internally handles it as one instance. If there was confusion hopefully that clears it up.

                NinjaScript is C#. All your classes, static variables, etc. behave how you would expect. This is something we do not support though. If you want to code at this level, by all means feel free to, but we can only be of limited assistance. We can only offer support on the NinjaScript aspect. e.g. using NinjaScript methods, properties, etc. Thank you for understanding.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Yes I do understand and that is fine.

                  However, it is obvious that certain coding goes on that you all don't officially support but is implicitly condoned. The primary example that comes to mind is the overriding of the Plot(...) method. I would very much like to see some explanation of how to best utilize this method (when should you call base.Plot, what to take into account when calculating canvas size and translating it to plot coordinates, etc).

                  There are also a number of other topics that you all classify as 'Advanced programming' related that would be helpful to have more information on.

                  Can you point me to the place where the advanced programmer would go to learn about using 'advanced' techniques? I am not talking about C# issues or .net issues. I specifically mean how to use things defined within the Ninja API.

                  Any help is appreciated.

                  Thanks,
                  Gary

                  Comment


                    #10
                    Gary,

                    I cannot direct you anywhere specific. What is discussed on the forums by forum members is what is available. These advanced features are not supported by NinjaTrader. Any use of them is done on your own. For the Plot() method please see the CustomPlotSample already installed with your NinjaTrader as an indicator. There is no additional information we can provide. Thank you for understanding.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Gary, if you really want to follow this path then what you need to do is pass data around outside the normal methods.

                      start here



                      I'm sure there are other ways of doing it as well.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by helpwanted, Today, 03:06 AM
                      1 response
                      12 views
                      0 likes
                      Last Post sarafuenonly123  
                      Started by Brevo, Today, 01:45 AM
                      0 responses
                      9 views
                      0 likes
                      Last Post Brevo
                      by Brevo
                       
                      Started by aussugardefender, Today, 01:07 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post aussugardefender  
                      Started by pvincent, 06-23-2022, 12:53 PM
                      14 responses
                      242 views
                      0 likes
                      Last Post Nyman
                      by Nyman
                       
                      Started by TraderG23, 12-08-2023, 07:56 AM
                      9 responses
                      387 views
                      1 like
                      Last Post Gavini
                      by Gavini
                       
                      Working...
                      X