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

override methods just work on the main indicator

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

    override methods just work on the main indicator

    Hey!

    Well... pretty much what the title says...

    I initialize the indicator B inside indicator A.
    B is supposed to save data from OnMarketData and OnMarketDepth and they are not executed... same with OnBarUpdate

    So... Why they are not executed? And how can i fix this?


    Hope to hear some news soon.
    Best regards.

    #2
    Hello Fernand0,

    Thank you for your note.

    Without the full code we're unable to test on our end.

    If you'd like to provide the full code I can take a look and see if anything jumps out. Please use the following format.

    To export a NinjaScript from NinjaTrader 8 do the following:
    From the Control Center window select Tools -> Export -> NinjaScript...
    Click Add>Select the indicator>OK>Export.
    Then attach that file you saved; under My Docs>NT8>Bin>Custom>Select the downloaded .zip file.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      the output is always
      0
      0
      Attached Files

      Comment


        #4
        Hello Fernand0,

        This can be achieved by using static objects in a static class in a custom namespace. You could see the MySharedMethodsAddonExample.zip at the following link.



        Another option would be to expose the values from indicator A to indicator B using one of the three methods covered in the following sample,



        Please let us know if you need further assistance.
        Last edited by NinjaTrader_AlanP; 09-11-2018, 07:57 AM.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_AlanP View Post
          This can be achieved by using static objects in a static class in a custom namespace.
          No it can't.. i need data from OnMarketData, if OnMarketData is not triggered... there is no data to process...

          Originally posted by NinjaTrader_AlanP View Post
          Another option would be to expose the values from indicator A to indicator B
          What? A to B..? I need the data from B in A, but w.e.
          I saw the options... all of them don't trigger OnMarketData...

          The AddOn, i don't know... is kinda complex for few months programing in NT... I have no idea how to get the events of MarketData and DepthMarket in an AddOn...


          I don't see any solution to my problem...

          Comment


            #6
            Hello Fernand0,

            At the following link, you’ll see a sample which contains a Addon which has a public static variable SharedDouble. I meant to include this link in my previous post.



            Within the indicator in OnMarketData, you could set,
            NinjaTrader.NinjaScript.AddOns.MySharedMethods.Sha redDouble = 5;

            Then within the calling indicator you could check the value of this variable with
            If(NinjaTrader.NinjaScript.AddOns.MySharedMethods. SharedDouble==5)

            In both cases OnMarketData would have to be called to both set and retrieve the value of SharedDouble.

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_AlanP View Post
              Within the indicator in OnMarketData, you could set,
              NinjaTrader.NinjaScript.AddOns.MySharedMethods.Sha redDouble = 5;

              Then within the calling indicator you could check the value of this variable with
              If(NinjaTrader.NinjaScript.AddOns.MySharedMethods. SharedDouble==5)

              In both cases OnMarketData would have to be called to both set and retrieve the value of SharedDouble.
              That's the problem, OnMarketData is not called.

              I checked your code, i understand it, and again, i don't see a possible scenario where i have 2 indicators triggering OnMarketData.

              In the code you are using OnBarUpdate, and it's not the same than OnMarketData, so when i call the indicator IN THE STRATEGY, it will happen again: the indicator won't trigger OnMarketData... not even once...

              So check this out... (Files.rar)

              0
              0
              Again, because the first indicator called in the strategy... doesn't trigger OnMarketData...

              I have to end making calls, for both indicators, through the strategy...
              i.e... Strategy.cs
              public B b;
              ...
              b = new B();
              ...
              protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
              {
              A.Method(marketDataUpdate);
              B.Method(marketDataUpdate);
              }
              This is insane... please change this NOW, send the request

              The only way that i have to fix this(without putting all the codes together), is adding, separately, the indicators in the chart and draw objects as signals and read them..... and this is slow and a really wrong practice...

              Calling indicator's methods from OnMarketData of the strategy is even worse. In this case i'm putting the logic of the indicators in the Strategy, because is not just calling 1 method per indicator, i have to make each indicator interact with each other (this business has nothing to do with the Strategy).

              I have no idea what to do...
              Attached Files

              Comment


                #8
                Hello Fernand0,

                I have attached a sample strategy which calls an indicator which prints to the output window the last price from OnMarketData. I apply the strategy to a 60 minute chart with calculate set to OnBarClose, and the last price is constantly printed to the output window.

                This works in real time only.

                Could you please provide more information on why you could not set a static variable via the indicator in OnMarketData, and have either another indicator or strategy reference this variable?

                Are you expecting values when running historically?

                I look forward to your reply.
                Attached Files
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_AlanP View Post
                  Could you please provide more information on why you could not set a static variable via the indicator in OnMarketData, and have either another indicator or strategy reference this variable?
                  please show me how that works... because the compiler don't let me access to a static variable

                  Member 'NinjaTrader.NinjaScript.Indicators.aaMyTest.last' cannot be accessed with an instance reference; qualify it with a type name instead
                  'NinjaTrader.NinjaScript.Strategies.Strategy.aaMyT est()' is a 'method', which is not valid in the given context

                  Leaving that apart, why it started to work when you call the constructor..? but it does not work with an instance? If i change your code to create an instance, there is no output.
                  Last edited by Fernand0; 09-10-2018, 04:55 PM.

                  Comment


                    #10
                    Hello Fernand0,

                    A sample of how you can access a static variable can be found at the link below.
                    The reason nothing prints when you call aaMyTest() is because nothing is exposed from the indicator. You could try setting a plot in OnMarketData, see the SMA indicator for a example of how to set a plot.

                    Or you could use a static variable in an Addon. In the following sample you could open the indicator file and see how SharedDouble is set to 5. You could move this statement to your OnMarketData block in your indicator. Then see the strategy script in the sample and see in OnBarUpdate how this variable is referenced. You very easily could use this approach to do what you’re trying to do.



                    Please let us know if you need further assistance.
                    Alan P.NinjaTrader Customer Service

                    Comment


                      #11
                      Hey Alan..

                      I will try to code the indicator into an AddOn. It has more sense to be an AddOn considering that the only thing that does is to save changes of the 10 levels of Ask and Bid.... and then it reconstructs the entire structure to deliver to another "indicator"(which i think i will make it as an AddOn too) where it makes more complex processing to determine the final results.

                      Thanks for your time and patience.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by manitshah915, Today, 12:59 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post manitshah915  
                      Started by ursavent, Today, 12:54 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post ursavent  
                      Started by Mizzouman1, Today, 07:35 AM
                      3 responses
                      17 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by RubenCazorla, Today, 09:07 AM
                      2 responses
                      13 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by i019945nj, 12-14-2023, 06:41 AM
                      7 responses
                      82 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X