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

Inheritance and references

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

    Inheritance and references

    Hi, I have a question about inheritance in NT8 strategies. I have a strategy TestA, that inherits code from a strategy TestB. When both are kept in a source code, then it works great.
    I would like to export TestB to an assembly, then remove a source code of TestB and set in TestA to inherit code from that assembly. I'm trying to set TestB.dll in References, but the TestA doesn't see inheritet variables.
    Is it possible to do it in NT8?
    I've attached a sample source code and a compiled assembly. I'm using NT 8.0.9.0.
    Attached Files

    #2
    Hello,

    Thank you for the post.

    In this case, I wouldn't necessarily suggest inheriting from another strategy directly if you are trying to share a method, properties or data.

    I would likely suggest using a class from the addon folder with some static properties. I have included an example of a class and properties below along with information on how to call that from your strategies. When exporting a shared item like this, you would need to have 3 exports. 1 for the class in the addons folder, and 1 for each strategy. After exporting the class, you could import the dll for it, and then start using the class in your strategies. When exporting the strategies, you would select the reference to the class along with your strategy in the export screen.


    First, create a new addon and remove the existing code leaving the using statements at the top. Paste the following:

    Code:
    namespace NinjaTrader.NinjaScript.AddOns
    {
    	public class ShareDataClass 
    	{
    		public static int SomeIntValue = 33; 
    		public static int IntPropety {get;set;}
    		public static double AReturnMethod()
    		{
    			return 1024.25;	
    		}
    	}
    }

    After exporting this addon/class as a compiled assembly, remove the source code and re-import the compiled assembly.

    Now from your strategies, you can access this using the following syntax;

    Code:
    Print(NinjaTrader.NinjaScript.AddOns.SharedData.SomeIntValue);
    Ensuring to use the full namespace like shown above will prevent reference errors when exporting and importing.



    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ScottWalsh, Today, 06:52 PM
    2 responses
    15 views
    0 likes
    Last Post ScottWalsh  
    Started by cre8able, Today, 07:24 PM
    0 responses
    0 views
    0 likes
    Last Post cre8able  
    Started by Haiasi, Today, 06:53 PM
    1 response
    4 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by ScottW, Today, 06:09 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by ftsc2022, 10-25-2022, 12:03 PM
    5 responses
    256 views
    0 likes
    Last Post KeyonMatthews  
    Working...
    X