• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 Jakub, Yesterday, 11:52 AM
    1 response
    16 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Started by dltharpe, Yesterday, 09:17 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Started by Johnny Santiago, 10-11-2019, 08:21 AM
    7 responses
    109 views
    0 likes
    Last Post FMtrader  
    Started by HiddenPhilosopher, Today, 04:37 AM
    0 responses
    7 views
    0 likes
    Last Post HiddenPhilosopher  
    Started by Gerik, Today, 04:09 AM
    0 responses
    3 views
    0 likes
    Last Post Gerik
    by Gerik
     
    Working...
    X