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

Instrument Selector in the input parameter settings of a strategy

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

    Instrument Selector in the input parameter settings of a strategy


    Hi Ninja Experts,

    I am building a custom strategy for which I need to provide an instrument selector and a bars period type selector as input parameter settings. The user will choose instrument and its bars period type for use in the trade logic. Through the below mentioned code, I have been able to achieve bars period type selection as input of strategy. However, when I try the same thing with InstrumentSelector, the code gets compiled successfully but object reference set to null exception while trying to configure the strategy. I have tried several things but not getting the objective.Please help me out with some correction or a template code. I would be grateful for your kind help.

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class ABC : Strategy
    {
    private BarsPeriodType bptOne;
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    bptOne = BarsPeriodType.Range;
    }
    }

    region Properties
    [NinjaScriptProperty, Display(Name="Bar Type", GroupName="Parameters", Order = 2)]
    public BarsPeriodType BPTONE
    {
    get{ return bptOne; }
    set{ bptOne = value; }
    }
    #endregion
    }
    }​

    Best Regards,
    Mubeen Haider


    #2
    Hello Mubeen Haider,

    A public Instrument using the NinjaTrader.Gui.Tools.InstrumentSelector attribute and XmlIgnore() attribute.

    See the post below.
    Hi, I've looked at this page on Instrument Selectors (https://ninjatrader.com/support/helpGuides/nt8/?instrumentselector.htm): ... but I don't want to create an addon or do the stuff re linking to other windows ... I just want a control in my indicator/strategy grid to select a secondary instrument. Is this possible? Regards,


    Where the property is used, be sure to check the value is not null.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      What a splendid support ChelseaB, so kind of you.

      It works fine but a little more help from your expertise. Please see the attached screenshot. The instrument selector is probably showing the name of exchange along with the instrument name which is not typically shown in an instrument selector while plotting a chart. I tried to set the default values in SetDefaults using the statement:

      InstrumentInput = Instrument.GetInstrument("NQ 12-22" );

      But the result remained the same as shown in screenshot. Can you please help me a little further to get normal instrument names as NQ 12-22 in the instrument selector instead of NQ 12-22 Globex

      Again thankful for your support.
      Attached Files

      Comment


        #4
        Hello Mubeen Haider,

        This shows up with the Instrument object type. However, from my understanding you can safely ignore the exchange.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          I found this thread on a search since I had a similar problem, just not with a strategy but an indicator. I applied the solution as suggested, and the instrument selector appeared in the indicator properties. However, once an instrument has been selected, it will always put the last selected instrument as the start value, even on new indicator instances and even though I initialized InstrumentInput = null in OnStateChange() when State == State.SetDefaults.

          It seems InstrumentSelector stores the last used instrument in UI.xml under <LastUsedInstrument> and always initializes with this value once it has been set.

          Is there a possibility to make it always start with an empty selection?

          Regards,
          Heiko

          Comment


            #6
            Hello Heiko,

            The InstrumentSelector itself (not the Instrument variable) is added by NinjaTrader behind the scenes.

            It might be possible to change the controls selection when overriding the PropertyDescriptorCollection in a custom type converter.

            Below is a link to the reference sample example of a type converter.


            This would be very advanced, and I'm not certain this will be achievable. There can be limitations using advanced C# concepts in NinjaScript, so your mileage may vary. As of now, we do not have any examples that can be used to navigate this specific path.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              NinjaTrader_ChelseaB or NinjaTrader_BrandonH Hi do you have samples references for the following:

              I'm looking to add a 2nd instrument selector to the chart window, or to a separate addon window.
              The function would be to quickly select 2 instruments and based on a condition place orders to both instruments simultaneously.
              I'd need 2 quantity selectors too for both instruments.
              I found about the AddDataSeries caveat Jesse mentions.
              Can you advise the best course to take for the sought purpose?
              With addon or strategy sample and reference if possible.
              Thanks in davance.

              Comment


                #8
                Originally posted by PaulMohn View Post
                NinjaTrader_ChelseaB or NinjaTrader_BrandonH Hi do you have samples references for the following:

                I'm looking to add a 2nd instrument selector to the chart window, or to a separate addon window.
                The function would be to quickly select 2 instruments and based on a condition place orders to both instruments simultaneously.
                I'd need 2 quantity selectors too for both instruments.
                I found about the AddDataSeries caveat Jesse mentions.
                Can you advise the best course to take for the sought purpose?
                With addon or strategy sample and reference if possible.
                Thanks in davance.
                NinjaTrader_ChelseaB or NinjaTrader_BrandonH

                Comment


                  #9
                  Hello PaulMohn,

                  ProfitChaseStopTrailAddonExample is an example with addon window that adds an InstrumentSelector.


                  An InstrumentSelector would also be created the same if adding to the UserControlCollection.

                  Dynamically calling AddDataSeries() with variables or branching logic is not supported, so this control would not be used to add a secondary series. But you could use this with a BarsRequest.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello Chelsea,

                    Thanks for the addon reference. I'm not finding the indicator in the indicators menu and cannot load it on the chart..
                    I tested loading the strategy but it does not show an extra instrument selector on the chart window.

                    I want to add a 2nd instrument selector to the ChartTrader.
                    For example:
                    I have ES 03-23 on a 5min chart.
                    I want to add NQ 02-23 5min chart (or just NQ 03-23 without timeframe) in a 2nd instrument selector located on the ChartTrader.


                    End use would be to change the instruments in both instrument selectors manually.
                    For example, on the same chart, I change via dropdown ES 03-23 to GC 04-23,
                    the same for NQ 03-23 to CL 03-23.

                    Then the same to the quantity selectors.

                    Finally I want to trigger orders on both selected instruments at the same time.

                    What sample / doc / reference / experience do you recommend?

                    Comment


                      #11
                      Hello PaulMohn,

                      "I'm not finding the indicator in the indicators menu and cannot load it on the chart.."

                      Are you referring to the DynamicBarsRequestExample indicator? This will be in the DataManagementExamples folder once imported.
                      This opens a window that allows you to enter a new instrument, and then does the bars request.

                      You can add an InstrumentSelector to chart trader. There is no example of this, but the ProfitChaseStopTrailAddonExample addon window (opened from the New menu on the Control Center) shows how to generate a new InstrumentSelector object and add it to the WPF of the window.
                      The SampleWPFModifications example demonstrates how to add controls to the chart trader area.

                      "Finally I want to trigger orders on both selected instruments at the same time."

                      This would have to be done through the Addon approach using an Account object, as a strategy cannot have an instrument added dynamically with AddDataSeries, and won't be able to place orders to a different instrument (unless the AddDataSeries() instrument is hard coded).
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks NinjaTrader_ChelseaB
                        This link is dead https://ninjatrader.com/downloads/ni...quest_nt8.zip/
                        iIs it accessible elsewhere?

                        Comment


                          #13
                          Hello PaulMohn,

                          You can also find this indicator here:
                          Chelsea B.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by alifarahani, Today, 09:40 AM
                          6 responses
                          29 views
                          0 likes
                          Last Post alifarahani  
                          Started by Waxavi, Today, 02:10 AM
                          1 response
                          17 views
                          0 likes
                          Last Post NinjaTrader_LuisH  
                          Started by Kaledus, Today, 01:29 PM
                          5 responses
                          13 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by Waxavi, Today, 02:00 AM
                          1 response
                          12 views
                          0 likes
                          Last Post NinjaTrader_LuisH  
                          Started by gentlebenthebear, Today, 01:30 AM
                          3 responses
                          17 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Working...
                          X