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 Max238, Today, 01:28 AM
    2 responses
    26 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by Shansen, 08-30-2019, 10:18 PM
    25 responses
    949 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by JonesJoker, 04-22-2024, 12:23 PM
    8 responses
    41 views
    0 likes
    Last Post JonesJoker  
    Started by timko, Today, 06:45 AM
    0 responses
    4 views
    0 likes
    Last Post timko
    by timko
     
    Started by Waxavi, 04-19-2024, 02:10 AM
    2 responses
    39 views
    0 likes
    Last Post poeds
    by poeds
     
    Working...
    X