Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TickSize in Strategy Extension Method

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

  • Zeos6
    replied
    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.

    Leave a comment:


  • NinjaTrader_ChrisL
    replied
    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.

    Leave a comment:


  • Zeos6
    replied
    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?

    Leave a comment:


  • Zeos6
    replied
    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.

    Leave a comment:


  • NinjaTrader_ChrisL
    replied
    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.

    Leave a comment:


  • Zeos6
    replied
    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.

    Leave a comment:


  • NinjaTrader_ChrisL
    replied
    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.

    Leave a comment:


  • Zeos6
    started a topic TickSize in Strategy Extension Method

    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.

Latest Posts

Collapse

Topics Statistics Last Post
Started by Revazi123, Today, 01:01 PM
0 responses
3 views
0 likes
Last Post Revazi123  
Started by sushilake, Today, 12:21 PM
0 responses
5 views
0 likes
Last Post sushilake  
Started by AaronKoRn, Today, 10:17 AM
0 responses
6 views
0 likes
Last Post AaronKoRn  
Started by PWillard, Today, 10:02 AM
0 responses
7 views
0 likes
Last Post PWillard  
Started by jmezz, 09-11-2020, 09:12 AM
2 responses
76 views
0 likes
Last Post stafe
by stafe
 
Working...
X