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

Want to launch non Indicator/Strategy code when NT 8 Starts

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

    Want to launch non Indicator/Strategy code when NT 8 Starts

    I have a bunch of code in NT 7 that loads internal C# Lists from an external SQL database, and want to do this with the new feature of NT 8 that apparently allows code to run outside of an Indicator or Strategy. Are there any samples of starting up code with the Control Center, and where to put it, et cetera? To me the documentation is not clear... Thanks

    #2
    Hello,

    Thank you for the post.

    You can now use the Addon base to execute code outside of a chart, this is generally invoked from the control centers menu but you can make background addons as well.

    We have a fairly thorough guide along with some complete samples at the following links:





    From the first link, there are two samples:
    "Download AddOn Framework NinjaScript Basic file to your desktop"
    "Download Visual Studio Solution for AddOn Development"

    The first is a complete addon that you import into the platform and edit from the platform. This displays the available ninjatrader controls and a window/control center menu item.

    The second is a visual studio project that builds a ninjatrader compatible dll.
    I would only suggest working with the second project for final export purposes and only if needed as you need to restart the platform to see any changes made.

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

    Comment


      #3
      reply

      Hello, Thank you. Is there one specific example I can quickly clone? What I want to do is when the Control Center starts to launch a background process, preferably in another thread. I have two of these...one can terminate when it completes its one time work...the other is a continuous background process that will be active as long as the Control Center is up. I'm trying to go forward with specific items and not get into a learning situation at the moment. Many thanks

      Comment


        #4
        Hello,

        I had noted in the prior reply the samples we have on this concept, here they are again:


        From the first link, there are two samples:
        "Download AddOn Framework NinjaScript Basic file to your desktop"
        "Download Visual Studio Solution for AddOn Development"
        I would suggest reviewing the samples on this page and see how they are coded to see how an addon works, that is really the best way to see all of what is required to create a full addon.

        Alternatively, you can just generate a new addon from the NinjaScript editor and explore further using the NinjaScript editor and output window. It sounds like you are just using C# items so this is likely the easiest way to get started.

        I would still suggest reviewing the help guide to understand the lifecycle/ overrides/ and other features offered by add-ons as they can certainly help or prevent ideas depending on what the end goal is. Addons do work differently than indicators or strategies in a few aspects so if you will be interfacing with any NinjaScript methods or data, the help guide and mentioned samples will likely be needed. If you are strictly only doing C# related tasks, creating an empty addon is likely the fastest approach if you don't want to try to learn addons further.

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          one step forward

          Ok, it looks like the AddOn OnStateChange(), either SetDefaults or Configure will give me the hook. Next issue: I need to share "public static" variables across all Indicators, Strategies, and AddOns....but it seems that the AddOn scope does not see these in a "public static class Common" that in NT7 I had to put in the Indicator folder (worked Ok and would share with Strategies). If I put the class in AddOn then the Indicator or Strategy cannot see it???? So.... How can I share common "system" (my system) variables across all objects in NT8? Thanks!

          Comment


            #6
            Hello,

            Thank you for the reply.

            Because we are using C# you can use namespaces to declare a static class from a .cs file in the addon folder. The Addon class its self is a special NinjaTrader type that has its states called for various reasons. The addon class should not be static but you could just declare a class in the same file if you wanted or in a separate file. Here is an example of that specifically: https://ninjatrader.com/support/foru...24&postcount=3

            In the example an addon file is used, it just has a static class in it along with a blank addon class to demonstrate placement. That static class has a property which has a value that is set/get from other indicator/strategy files.

            Please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              clarification

              Hello, I see the { get; set; } in the AddOn class. That seems to indicate that public AddOn classes are private with respect to Indicators and Strategies. Is that so? Then, is there any way to set the { get; set;} at the class level? I have a huge amount of shared variables in this class. Thanks

              Comment


                #8
                Hello,

                Thank you for the reply.

                The get; set; would have nothing to do with the access modifier or what NinjaScript types can see this class, the property is public in the sample as well as the addon:

                Code:
                [B]public[/B] class TestShareData : NinjaTrader.NinjaScript.AddOnBase
                	{
                		protected override void OnStateChange()
                		{
                			if (State == State.SetDefaults)
                			{
                				Description							= @"Enter the description for your new custom Add on here.";
                				Name								= "TestShareData";
                			}
                			else if (State == State.Configure)
                			{
                			}
                		}
                	}
                	
                	[B]public[/B] static class SharedData {
                		[B]public[/B] static double TestDouble { get; set; }
                	}
                If this is the code you are referring to, the access modifier is public which is listed on the left in bold on both the static class and the dummy addon class.

                The indicator or strategy or any other item would then access this using its fullname or property name with namespace prepending it:

                Code:
                NinjaTrader.NinjaScript.AddOns.SharedData.TestDouble = 100;
                The addon class specifically was not used at all in this example, again the addon class was only used to show placement of the static class. Your properties would go in the static class. In fact, you could remove the addon class altogether if the goal is simply to have a class of properties.

                The syntax { get; set; } is a way of defining a property that has no backing field or private variable attached to it. You will see this commonly in NinjaScript for properties. If you do need a backing field, it would look like the following:

                Code:
                public static class SharedData {
                        private static double myBackingField;
                	public static double TestDouble { get { return myBackingField; } set { myBackingField = value; } }
                	}
                None of these concepts would be NinjaScript specific also, static and public properties are C# concepts so the addon class should have nothing to do with making a static class that has properties, it is simply shown for placement in that example.

                Please let me know if I may be of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  success!

                  Ok, thanks for being patient... I finally have it working...moved the public static variables into a non-ninja namespace/class in CS file in AddOns. And, then it is relatively simple....in an AddOn...to load data from SQL tables during the Ninja startup protected override void OnStateChange() { if (State == State.SetDefaults) { } else if (State == State.Configure) { t1 = new Thread (new ThreadStart (LoadSQLData)); t1.Start(); } }

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by TraderBCL, Today, 04:38 AM
                  2 responses
                  6 views
                  0 likes
                  Last Post TraderBCL  
                  Started by martin70, 03-24-2023, 04:58 AM
                  14 responses
                  105 views
                  0 likes
                  Last Post martin70  
                  Started by Radano, 06-10-2021, 01:40 AM
                  19 responses
                  606 views
                  0 likes
                  Last Post Radano
                  by Radano
                   
                  Started by KenneGaray, Today, 03:48 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post KenneGaray  
                  Started by thanajo, 05-04-2021, 02:11 AM
                  4 responses
                  471 views
                  0 likes
                  Last Post tradingnasdaqprueba  
                  Working...
                  X