Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

adjustments to strategy for distribution.

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

    adjustments to strategy for distribution.




    people with nt,



    i am preparing some automated strategies i have developed for distribution.



    i have spoken with some nt employees about these subjects so i already have a basic understanding of the tools that the nt platform has available to restrict the use of a strategy only to paying clients.



    however, my strategies are intended to be traded only on specific instruments, on an account with a given minimum capital available and with defined position sizes. this means that i want to incorporate code to my strategies so that the strategy will only run if all conditions are valid. i imagine nt must have the capability to deliver every one of these requirements.


    ¿how can one limit a strategy to only run if the chart or instrument it has been enabled on is the nq futures contract? ¿and is that also possible for the mnq futures contract?


    similarly, ¿is it possible to have a check for available capital in the account? and this could be a little more complex than it seems. i would like to have an initial check on the first day the strategy is enabled to verify the available capital is above $50,000 usd, and then check every day that the available capital is still above $40,000 usd.


    and the strategy would always trade in multiples of 2. so the smallest position size would be 2, then 4, 6 and so on. i don't think that would be hard, however, i would like to offer clients the possibility to trade smaller (never larger) position sizes than their account can accommodate. so, a client that has enough capital to trade 6 contracts could trade only 2 contracts if they so choose. i imagine i could create a calculation with the available capital divided by the minimum i set for every 2 contracts and then check use an input the client could choose but only if it is not greater than the previously calculated variable.


    i should be enrolled in the vendor program before one or two days, so these are some adjustments that i want to complete as soon as possible. very well, regards.


    #2
    You can use Instrument.MasterInstrument.Name to find the symbol. So if you wanted to limit it to specific Instruments, I would assume a simple boolean being equal to "NQ" or "MNQ" would suffice.

    I haven't attempted to check the account value, but I'm sure that should be possible? I only add a question mark to that as I have yet to reliably retrieve the commissions from the account I happen to be on. It seems the workaround I am using has a variable that is set for strategy purposes.

    As for trading in multiples of 2. That is more than possible. I currently have code to limit my trades to roughly $50 per trade and it calculates the amount needed in that instance. I also have code that limits the total max contracts at any given time as 60. So any more, and it won't take the trade. If I have a trade that can have at most 10 lots, and I already have 53 being traded, it will adjust to 7.

    I'm sure there are a handful of things that you might not be able to do due to limitations with NT itself or c#. There are usually ways to code these things, the problem most of the time is if you don't know how to create the logic for what you want to attempt.

    Comment


      #3
      Originally posted by rockmanx00 View Post
      You can use Instrument.MasterInstrument.Name to find the symbol. So if you wanted to limit it to specific Instruments, I would assume a simple boolean being equal to "NQ" or "MNQ" would suffice.

      I haven't attempted to check the account value, but I'm sure that should be possible? I only add a question mark to that as I have yet to reliably retrieve the commissions from the account I happen to be on. It seems the workaround I am using has a variable that is set for strategy purposes.

      As for trading in multiples of 2. That is more than possible. I currently have code to limit my trades to roughly $50 per trade and it calculates the amount needed in that instance. I also have code that limits the total max contracts at any given time as 60. So any more, and it won't take the trade. If I have a trade that can have at most 10 lots, and I already have 53 being traded, it will adjust to 7.

      I'm sure there are a handful of things that you might not be able to do due to limitations with NT itself or c#. There are usually ways to code these things, the problem most of the time is if you don't know how to create the logic for what you want to attempt.



      thanks.



      i agree. nt is a powerful platform, it is possible to code a lot of different capabilities.



      the checks will probably look something like:


      _ if instrument =/ nq then return;


      _ if accountsize < requiredcapital then return;


      _ positionsizetotrade = 2 * min { user input, calculationformaximumpositionsizeinpairs } ; where the user would choose the number of pairs.



      however, there could be multiple ways to code these checks and the nt staff should be far more knowledgeable on how to create this code and in which section to place it.

      Comment


        #4
        Yes. If you are trying to code this, Google is also a very good resource, especially since Ninjascript is C# based. The key is if you want to understand something that is more C# specific, try googling what you want and specify C#. If you want something that is more Ninjatrader related, then make sure to add either ninjatrader or even ninjascript. Many times you will see the results pop up something from these forums as well. You may not find the exact solution, but you may find some hints that'll get you on track.

        Comment


          #5
          Hello rtwave,

          rockmanx00 is providing good information.

          Below are links to the Desktop SDK which provide the specific documentation.

          Instrument.FullName - https://developer.ninjatrader.com/docs/desktop/fullname
          Account.Get() - https://developer.ninjatrader.com/docs/desktop/get
          AccountItem - https://developer.ninjatrader.com/do...op/accountitem

          As well as the microsoft documentation on Math.Min().


          You could add your conditions to State.Configure logic block in OnStateChange() and if the condition fails call SetState(State.Terminated) to disable the script.
          Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


          I would also recommend calling Log() first to inform the user what is going on.
          Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

          Chelsea B.NinjaTrader Customer Service

          Comment


            #6


            i have decided on two strategies i will be leasing through the nt ecosystem.


            this if the first one, i decided to call it _ short and long strategies nasdaq strategy level 2 of 4 _.


            Click image for larger version

Name:	20250209-d-mnq-sls-l2-0001.jpg
Views:	179
Size:	36.4 KB
ID:	1334292

            Click image for larger version

Name:	20250209-d-mnq-sls-l2-0002.jpg
Views:	175
Size:	79.6 KB
ID:	1334293

            Click image for larger version

Name:	20250209-d-mnq-sls-l2-0003.jpg
Views:	171
Size:	91.1 KB
ID:	1334294

            Comment


              #7

              this if the second one, _ short and long strategies nasdaq strategy level 3 of 4 _.

              Click image for larger version

Name:	20250209-d-mnq-sls-l3-0001.jpg
Views:	180
Size:	36.4 KB
ID:	1334296


              Click image for larger version

Name:	20250209-d-mnq-sls-l3-0002.jpg
Views:	171
Size:	79.1 KB
ID:	1334297

              Click image for larger version

Name:	20250209-d-mnq-sls-l3-0003.jpg
Views:	165
Size:	93.7 KB
ID:	1334298

              Comment


                #8

                these strategies are ready to be enabled on my account, but not yet to distribute to other individuals. therefore, i have some more questions for nt staff.



                the most relevant question is, ¿what are the possible ways to distribute a strategy? ¿will i have to create a workspace and then distribute that file in addition to the files for the strategy? ¿is it possible to only disseminate the files for the strategy itself?


                and related to this, ¿how can indicators be distributed? ¿is it possible to transform an indicator into a function or some other formulation such that it will only perform the required calculations inside a strategy? the idea is to distribute code that will not plot in a chart and could not be used for any other purpose outside of the strategy.


                and my last question for the moment, i plan to create files to distribute once per month. i think that it should be possible to distribute files to every client so that the strategy would only function for the period that has already been paid for. in this case, ¿what kind of code should i use? i imagine something like if date < start date or date > end date then terminate.


                very well, regards.
                Last edited by rtwave; 02-11-2025, 09:49 AM.

                Comment


                  #9
                  Hello rtwave,

                  You can export your code as an assembly (.dll) to prevent this code from being read or modified, and optionally you can use Agile.NET to prevent the code from being un-assembled (deobfuscated).

                  To export your script do the following:
                  1. Click Tools -> Export -> NinjaScript
                  2. Click the 'add' link -> check the box(es) for the script(s) you want to include -> click OK
                  3. Check the option labelled 'Export as compiled assembly'
                  4. If you have Agile.NET installed and would like to use this, check the box labelled Protect compiled assembly
                  5. Click Export -> enter a unique name for the file in the Dialog window
                  6. Choose a save location -> click Save
                  7. Click OK to clear the export location message
                  By default your exported file will be in the following location:
                  • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
                  Below is a link to the help guide on Exporting NinjaScripts.
                  Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


                  As well as a link to the Distribution section of the Desktop SDK.
                  https://developer.ninjatrader.com/do...p/distribution

                  Below is a link to the help guide on Agile.NET protection.
                  Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


                  You can purchase Agile.NET here.
                  http://www.secureteam.net/ninja-pricing

                  You can include workspace xml files in a folder named workspaces manually added to the export zip file and these will import when importing the export zip.
                  Your templates are stored in the NinjaTrader settings folder in:
                  • (My) Documents\NinjaTrader 8\workspaces​
                  You can also include templates with the export.
                  Your templates are stored in the NinjaTrader settings folder in:
                  • (My) Documents\NinjaTrader 8\templates
                  ​Below is a link to a short to an older video to demonstrate.



                  You can expose values to a host that are not intended to plot​.

                  Below is a link to the reference sample which demonstrates.
                  Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.



                  The Vendor License Management Console allows for expiring licenses after a preset amount of time.
                  I would recommend you use incrementing version numbers in the export window to keep track of which release is the latest.

                  I also recommend isolating any shared dependencies to separate files. Below is a link to a video demonstrating.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10



                    people with nt,




                    i want to incorporate several checks to my strategies in order to distribute them. it should only be possible to enable the strategy if the account number, account cash value, instrument and date of the year are valid values.


                    i have found that these prints will work without problem and return readable values.


                    Print(Account.Name);
                    Print(AccountItem.CashValue);
                    Print(Bars.Instrument.MasterInstrument.Name);



                    however, the checks i am trying to use will not work. account name and instrument name will return strings and an error message states that the =! operand cannot be applied to strings.


                    if (Account.Name =! Account.Name)
                    {
                    SetState(State.Terminated);
                    return;
                    }


                    if (Account.Get(AccountItem.CashValue, Currency.UsDollar) < 1)
                    {
                    SetState(State.Terminated);
                    return;
                    }


                    if (Bars.Instrument.MasterInstrument.Name =! "RTY")
                    {
                    SetState(State.Terminated);
                    return;
                    }​



                    i have not found any examples or information on where to incorporate these checks. the onstatechange section has several subsections and i have no idea where i should insert the checks.


                    the last check would be for today's date and i think this one should work as intended:




                    if (ToDay(Time[0]) > 20250430)
                    {
                    SetState(State.Terminated);
                    return;
                    }​


                    the documentation and information is really lacking so i ask that nt provide some working samples of how anyone should do to incorporate checks of this kind to a file.


                    regards.

                    Comment


                      #11
                      Hello rtwave,

                      With C# you will need to use !=, +=, <=, >=.
                      This chapter covers operators and expressions. Expressions form several groups, including primary expressions, unary operators, arithmetic operators, relational and type testing operators, and logical operators.


                      For example:
                      if (Account.Name != "Sim101")

                      Many of these checks are ok to put in OnStateChange() in the State.DataLoaded logic block.

                      The check for the bar time however would not be suitable for OnStateChange() and would need to be placed in the OnBarUpdate block.
                      Alternatively, you could use Core.Globals.Now in place of Time[0] and that would be suitable for OnStateChange().

                      I would also recommend sending a Log() or Print() message to inform the user why the script is being disabled.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12


                        people with nt,


                        i have one more question, ¿is there any identifier for a nt brokerage account other than account name? i think that account number would be much better.





                        and, i think i finally have been able to get this code to work. as always, i share the code in case it could be helpful for someone else:


                        protected override void OnStateChange()
                        {​

                        else if (State == State.DataLoaded)
                        {


                        if (Account.Name != Account.Name)
                        {
                        Log("message.", LogLevel.Alert);
                        SetState(State.Terminated);
                        return;
                        }


                        if (Account.Get(AccountItem.CashValue, Currency.UsDollar) < 11000)
                        {
                        Log("message.", LogLevel.Alert);
                        SetState(State.Terminated);
                        return;
                        }


                        if (Bars.Instrument.MasterInstrument.Name != "RTY")
                        {
                        Log("message.", LogLevel.Alert);
                        SetState(State.Terminated);
                        return;
                        }

                        if (ToDay(Core.Globals.Now) > 20250601)
                        {
                        Log("message.", LogLevel.Alert);
                        SetState(State.Terminated);
                        return;
                        }

                        }​

                        Comment


                          #13
                          Hello rtwave,

                          The account number is not provided to NinjaTrader. There is an internally used Id.

                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          598 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          343 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          103 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          557 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          556 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X