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

TickSize in Strategy Extension Method

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

    TickSize in Strategy Extension Method

    Hi ,

    In my strategy I created a separate namespace in which I house some extension methods. Is there a way for me to access the TickSize value for the instrument inside the extension method? If so, how? I would prefer to use a fully qualified name to access it rather than passing it as a parameter. Please advise. Thank you.

    #2
    Hello Zeos6, thanks for writing in.

    The TickSize property comes from the NinjaScriptBase class, all indicators and strategies inherit from the NinjaScriptBase class, so you would need to pass in either the StrategyBase object from the strategy or pass in the TickSize value itself.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,

      Thank you or your reply. Can you please elaborate a bit.. I must be missing something as your suggestion does not work.

      double tickSize = NinjaTrader.NinjaScript.Trategy.xxxx doesn't work
      double tickSize = NinjaTrader.NinjaScript.StrategyBase.xxxx doesn't work.

      Comment


        #4
        Hello Zeos6, thanks for your reply.

        It depends on how the extension methods are used/ how they are implemented. If they are global methods that any script can call, you would need to pass in the StrategyBase when calling the method from a strategy:

        https://pastebin.com/mCD1kU8h - helper class example

        then, in the calling strategy:
        OnBarUpdate()
        {
        Print(Helpers.GetTickSize(this));
        }

        Please let me know if this does not resolve your inquiry.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi Chris,

          Interesting approach but it won't work for my purposes. I don't want to access this type of helper method from OnBarUpdate(). In fact, I only want to access the TickSize inside an extension method and I don't want to call it from OnBarUpdate(). Any way this can be done?

          I tried creating an instance of NinjaTrader.NinjaScript.NinjaScriptBase but it is an abstract class or an interface, so that was a no go.

          Comment


            #6
            EDIT:

            The only way to get it to work was to create a new instance of the strategy inside the extension method.

            NinjaTrader.NinjaScript.Strategies.PB.PB_Strategy pbs = new NinjaTrader.NinjaScript.Strategies.PB.PB_Strategy( );
            double tickSize = pbs.TickSize;

            Is there a better/cleaner way of doing this?

            Comment


              #7
              Hello Zeos6, thanks for your reply.

              NinjaTrader sets up the Strategy and Indicator objects for us using what is called a "factory". We never actually use "new Strategy" or "new Indicator" because the NinjaTrader core sets up the object for us, and also sets up the instrument context the strategy or indicator is applied to. Unfortunately, there is no documentation for properly setting up an instrument context for an indicator or strategy object, because NinjaTrader sets that stuff up automatically. The most straight forward way of doing it would be to pass in the StrategyBase or IndicatorBase context. For a supported way of getting Instrument information, one must develop this as a NinjaScript Addon. See the "Data Access" section of the sample we have on making addons, starting at line 393 of the "AddOn Framework NinjaScript Basic" example:

              https://ninjatrader.com/support/help...t_overview.htm

              Please let me know if you have any questions on this material.
              Chris L.NinjaTrader Customer Service

              Comment


                #8
                Thanks Chris. I understand re the factory approach. It would be nice to do access this outside the indicator/strategy itself, especially for such basic things as instrument information.
                I will have a look at the add on information but that is a bit of overkill in my case. I will also have a second look at passing in the instance via 'this', as you suggested earlier in your helper method. I know that my hack works, even if it is not clean or optimal.

                Thanks for all your help. Appreciate it.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by trilliantrader, 04-18-2024, 08:16 AM
                5 responses
                22 views
                0 likes
                Last Post trilliantrader  
                Started by Davidtowleii, Today, 12:15 AM
                0 responses
                3 views
                0 likes
                Last Post Davidtowleii  
                Started by guillembm, Yesterday, 11:25 AM
                2 responses
                9 views
                0 likes
                Last Post guillembm  
                Started by junkone, 04-21-2024, 07:17 AM
                9 responses
                70 views
                0 likes
                Last Post jeronymite  
                Started by mgco4you, Yesterday, 09:46 PM
                1 response
                14 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Working...
                X