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

Set multiple instruments in strategy via chart UI

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

    Set multiple instruments in strategy via chart UI

    Is it possible to directly set multiple instruments for a strategy via the strategy chart UI. I know that the chart will display multiple instruments and I know how to set this up through the UI. I know that by default the strategy will access the primary series. I do not want to hard code the secondary instrument name in an AddChart statement within the strategy. AddChart provides a facility for managing this with multiple time frames based on the same instrument, but not clear to me if (or how) to do it for multiple instruments using the same time frame.

    #2
    Hello jvanelli,

    Thanks for your post.

    When you create a script, correct it will use the charts primary series as the default data series for the script. If you want to access any other data (same or different instrument) you must use AddDataSeries() (Or variations that are bar type dependent).

    In the help guide for AddDataSeries, it provides a warning that relates: "Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner." Reference: https://ninjatrader.com/support/help...dataseries.htm So the bottom line is we can only recommend that you hardcode added data series.

    When you add one or more data series to your script you also need to consider other potential changes to your script, these are addressed in the help guide here: https://ninjatrader.com/support/help...nstruments.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Perhaps I could read the primary instrument name during State.Configure and then execute one of several hardcoded AddDataSeries() statements dependent upon the result. Thus when I change the primary series via the chart UI, the secondary series will be set by the script. I am not interested in making this universally applicable. I only need to deal with a small number of specific cases.

      Comment


        #4
        Originally posted by jvanelli View Post
        I do not want to hard code the secondary instrument name in an AddChart statement within the strategy.
        Did you try making it a property?

        Create a string property to contain the name of the instrument, then just enter this instrument name as one
        of your strategy parameters.

        First, use a string variable, like this, for the backing store of the property,

        private string instrumentName = "ES 09-19"; // <-- hardcode default name here

        Note that you can hardcode the default instrument name with your private variable, but since it's the backing
        store for the string property, you'll be able to see and modify the string value inside the strategy's property
        grid of parameters -- thus changing it to anything you want.

        Comment


          #5
          Hello jvanelli,

          Thanks for your reply.

          Originally posted by jvanelli View Post
          Perhaps I could read the primary instrument name during State.Configure and then execute one of several hardcoded AddDataSeries() statements dependent upon the result. Thus when I change the primary series via the chart UI, the secondary series will be set by the script. I am not interested in making this universally applicable. I only need to deal with a small number of specific cases.
          If your other added data series are of the same instrument as the chart bars, you can simply pass in null for the instrument name. reference: "4. For the instrument name parameter null could be passed in, resulting in the primary data series instrument being used." https://ninjatrader.com/support/help...dataseries.htm
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            I ended up doing something similar to what bltdavid suggested. My strategy makes indicative decisions based on primary instruments (ES, YM, 6E). I read the master instrument (FullName) from the UI in State.StateConfigure and use that to select from my short list of secondary series (i.e. the micro contracts). AddSeries happens in State.StateConfigure. I have a parameter input from the UI to choose between primary instrument or secondary series for trade executions. I trade those three markets almost exclusivley so this is all I need here. Also wanted to say that NT8 is a really nice piece of work, and the support via this forum is top notch.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DanielTynera, Today, 01:14 AM
            0 responses
            2 views
            0 likes
            Last Post DanielTynera  
            Started by yertle, 04-18-2024, 08:38 AM
            9 responses
            40 views
            0 likes
            Last Post yertle
            by yertle
             
            Started by techgetgame, Yesterday, 11:42 PM
            0 responses
            11 views
            0 likes
            Last Post techgetgame  
            Started by sephichapdson, Yesterday, 11:36 PM
            0 responses
            2 views
            0 likes
            Last Post sephichapdson  
            Started by bortz, 11-06-2023, 08:04 AM
            47 responses
            1,615 views
            0 likes
            Last Post aligator  
            Working...
            X