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.
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!
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
NinjaTrader
TickSize in Strategy Extension Method
Collapse
X
-
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.Tags: None
-
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
-
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
-
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
-
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
-
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
-
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
-
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 johntraderuser2, Today, 02:34 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
12 views
0 likes
|
Last Post Today, 02:00 AM | ||
Started by Mariawilcoxi, Today, 01:32 AM
|
0 responses
4 views
0 likes
|
Last Post
by Mariawilcoxi
Today, 01:32 AM
|
||
Started by gleichnerany, Today, 01:17 AM
|
0 responses
5 views
0 likes
|
Last Post
by gleichnerany
Today, 01:17 AM
|
||
Started by WHICKED, 03-27-2024, 12:33 PM
|
4 responses
47 views
0 likes
|
Last Post Today, 12:28 AM |
Comment