Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Instrument List as a Parameter?

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

    Instrument List as a Parameter?

    I'd like the user to be able to select an instrument from the defined instrument list, as a parameter in my strategy. Then in the State.Configure method, I'll add a barseries to the chart for that instrument.

    I am trying to create a parameter to allow selection of an instrument, but it's not working yet...

    Code:
            [NinjaScriptProperty]
            [Display(ResourceType = typeof(Custom.Resource), Name="Instrument 2", Description="Name of instrument 2, e.g. CL 11-16", Order=7, GroupName="NinjaScriptStrategyParameters")]
            public NinjaTrader.Cbi.InstrumentList Instrument2
            { get; set; }
    
    [...]
                    AddDataSeries(Instrument2.ToString(), Data.BarsPeriodType.Minute, 60, Data.MarketDataType.Last);

    Any ideas on how to do this?

    Thanks!
    Bryan
    cassb
    NinjaTrader Ecosystem Vendor - Logical Forex

    #2
    Hello cassb,

    There is not a supported way of achieving this, though this may be possible.

    Bascially, you would need to make a list of all Instruments by name, and then use a TypeConverter with the property.

    Using a custom TypeConverter is not supported in NinjaTrader 8 (or 7) so I do not have any educational resources to assist with this.

    However, there is a thread that discusses something similar for NinjaTrader 7 (making a drop-down for sounds).


    Basically the same thing would be needed for NinjaTrader 8.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      ha -- and what do you know? I was the one who asked that question in 2012. :-) Thanks!
      cassb
      NinjaTrader Ecosystem Vendor - Logical Forex

      Comment


        #4
        Hello cassb,

        I was able to use a type converter that already exists within NinjaTrader, so I've made an example I would like to share with you.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you, my friend for working on that for me. I'll take a look later today. :-)

          Bryan
          cassb
          NinjaTrader Ecosystem Vendor - Logical Forex

          Comment


            #6
            Thank you, that works great. Now I want to add that instrument to the chart and make it visible in the same Panel 1 as the main instrument. I tried this below, but I don't see it on the chart. I want it to be a line chart:

            Code:
                    protected override void OnStateChange()
                    {
                        if (State == State.SetDefaults)
                        {
                            Description                                    = @"";
                            Name                                        = "InstrumentSelectorInputExample";
                            Calculate                                    = Calculate.OnBarClose;
                            IsOverlay                                    = true;
                            DisplayInDataBox                            = true;
                            DrawOnPricePanel                            = true;
                            DrawHorizontalGridLines                        = true;
                            DrawVerticalGridLines                        = true;
                            PaintPriceMarkers                            = true;
                            ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                            //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                            //See Help Guide for additional information.
                            IsSuspendedWhileInactive                    = true;
                            InstrumentInput                                = Instrument.GetInstrument("AAPL");
                        }
                        else if (State == State.Historical)
                        {
                            Print(InstrumentInput.ToString());
                        }
                        else if (State == State.Configure)
                        {
                            AddDataSeries(InstrumentInput.ToString(), Data.BarsPeriodType.Minute, 60);
                        }
                    }
            cassb
            NinjaTrader Ecosystem Vendor - Logical Forex

            Comment


              #7
              Hello cassb,

              I'm not aware of any way to add a data series to a chart from a script.

              As an indicator you would need to custom render each bar in OnRender().

              This instrument select simply sets an instrument object to a value. The example prints the name of the instrument selected.

              AddDataSeries() adds a data series to the script for calculations. This does not add the data series to the chart.


              This works the same as the Add() method in NinjaTrader 7 when adding a secondary data series.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                OK, so you're saying if I want the instrument to be visible on the chart, I have to select it from chart's Data Series... menu and cannot do it from the Ninjascript?

                The idea here it to be able to trade and monitor both instruments from the same script. I don't know if it will work to just select two instruments on the same chart from the Data Series... menu without also AddDataSeries() in the code. If I don't use AddDataSeries, can I still EnterLong() on either or both of the instruments on the chart?
                Last edited by cassb; 11-02-2016, 08:34 AM.
                cassb
                NinjaTrader Ecosystem Vendor - Logical Forex

                Comment


                  #9
                  Cass, just specify which dataseries you are entering long in, ex. EnterLong(1, 5, "LongOnSeries1");
                  which enters long 5 contracts on the secondary bar series.
                  eDanny
                  NinjaTrader Ecosystem Vendor - Integrity Traders

                  Comment


                    #10
                    Hello cassb,

                    Using AddDataSeries does add the data to the script for use with placing orders to a second instrument and for getting data from a secondary instrument and / or time frame.

                    So yes, you can use this to make calculations and send orders.

                    But no, this does not visually add an additional bar series on the chart.

                    To place an order to a secondary series, use the BarsInProgress index of that series when placing the order.
                    EnterLong(int barsInProgressIndex, int quantity, string signalName)


                    Below is a link to an official reference sample that demonstrates how to add intra-bar granularity.
                    http://www.ninjatrader.com/support/f...ead.php?t=6652

                    Also, here is a link to the differences on real-time vs backtest (historical).
                    http://ninjatrader.com/support/helpG...ime_vs_bac.htm

                    As well as a link to the help guide on the AddDataSeries() method.
                    http://ninjatrader.com/support/helpG...dataseries.htm

                    A link to the help guide on BarsInProgress.
                    http://ninjatrader.com/support/helpG...inprogress.htm

                    And a link to the help guide on Multi-Time Frame & Instruments. Please see the section 'How Bar Data is Referenced', and 'Accessing the Price Data in a Multi-Bars NinjaScript'.
                    http://ninjatrader.com/support/helpG...nstruments.htm
                    Last edited by NinjaTrader_ChelseaB; 11-02-2016, 09:26 AM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Yes, I understand how to place orders on multiple bar series. But it sounds like I will have to both manually add the two instruments to the chart with the chart menu Data Series, and also add that same data series in the code with AddDataSeries() as well. So there's a chance I could mess up and put the wrong instrument onto the chart and pick the wrong instrument in the strategy parameter so that they don't match, no? I would be watching one instrument on the chart while the strategy is trading a completely different instrument?

                      Bryan
                      cassb
                      NinjaTrader Ecosystem Vendor - Logical Forex

                      Comment


                        #12
                        Cass, just specify which dataseries you are entering long in, ex. EnterLong(1, 5, "LongOnSeries1");
                        which enters long 5 contracts on the secondary bar series.
                        Hey Dan, how's it going? Long time no talk. :-)

                        See my post below about the answer to Chelsea's question...

                        Bryan
                        cassb
                        NinjaTrader Ecosystem Vendor - Logical Forex

                        Comment


                          #13
                          Hello Bryan,

                          Yes, you must manually add additional data series to a chart in the Data Series window from a chart.

                          No, AddDataSeries() does not visually add an additional bar series on the chart.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi Chelsea -- OK, so how about this idea, can a script access/trade all instruments on a chart without having to AddDataSeries()? I know the primary (first in the list?) instrument on the chart is what is used for OnBarUpdate. But would OnBarUpdate be called for all instruments on the chart, or just the primary instrument unless I AddDataSeries?
                            cassb
                            NinjaTrader Ecosystem Vendor - Logical Forex

                            Comment


                              #15
                              Hello Bryan,

                              Using the managed or unmanaged order methods, no, you would not be able to place an order to any instrument other than the instruments of the series added to the script, including the primary.

                              Using the Account.Submit() method available to Addons, you can submit an order to any instrument you want as long as you know the instrument.


                              That I know of, there are not any documented ways of listing the instruments that have been added to a chart.
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by samish18, Today, 01:01 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post samish18  
                              Started by WHICKED, Today, 12:56 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by Spiderbird, Today, 12:15 PM
                              2 responses
                              11 views
                              0 likes
                              Last Post Spiderbird  
                              Started by WHICKED, Today, 12:45 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post WHICKED
                              by WHICKED
                               
                              Started by FrazMann, Today, 11:21 AM
                              2 responses
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Working...
                              X