Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Inheritance and references

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

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

    Leave a comment:


  • InteRadek
    started a topic Inheritance and references

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by KevinWalker, Today, 07:48 PM
0 responses
3 views
0 likes
Last Post KevinWalker  
Started by WaveAtElliot, Today, 05:11 PM
1 response
10 views
1 like
Last Post hdge4u
by hdge4u
 
Started by bosajin, Yesterday, 09:15 AM
5 responses
40 views
0 likes
Last Post NinjaTrader_Jim  
Started by Dolfan, Today, 12:24 PM
4 responses
23 views
0 likes
Last Post NinjaTrader_Jim  
Started by WeyldFalcon, Today, 11:09 AM
7 responses
30 views
0 likes
Last Post WeyldFalcon  
Working...
X