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

Accessing Instrument Lists from within a strategy

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

    Accessing Instrument Lists from within a strategy

    I'd like to have a drop down list of all of my default instruments (or other instrument lists) as an option in the parameter list when launching a strategy. For example, if I'm launching a multi-instrument strategy on the chart of the front month ES contract, I'd like to have a drop down list of other valid ES contracts (or any other contracts in a given instrument list) available to select as a secondary instrument as opposed to hard coding the secondary instrument.

    Are the instrument lists accessible from within a strategy? Are there any methods available to auto select the next valid contract for a given instrument?

    Basically, I'm trying to avoid having to hard code additional instruments in a multi-instrument strategy. Thanks

    kc

    #2
    Hi kc, there are unfortunately no supported methods availalble for accessing the next expiry months for a contract or the symbol lists setup through the Instrument Manager.

    Via C# custom coding you could attempt reading the Instruments.txt file where the default instrument lists and rollover dates are stored.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by kcsystemtrader View Post
      Basically, I'm trying to avoid having to hard code additional instruments in a multi-instrument strategy. Thanks

      kc
      if i understood you correctly you can do the following, this will let you dynamically access the symbol name while putting on the strategy.

      in variable
      string symbolName = "ES 12-11";
      in initialize

      Add(symbolName,BarsPeriod.BasePeriodType,BarsPerio d.Value);

      and add a property

      [Description("Symbol Name")]
      [GridCategory("Parameters")]
      public string SymbolName
      {
      get{return symbolName;}
      set{symbolName = value;}
      }

      Comment


        #4
        Thanks. It seems to me that since NT already has the instruments list data and since these lists can be user defined, it would be nice if they were exposed for use by a strategy. Potential enhancement request.

        For now, I will expanding on bukkan's idea hard code them. I think an enum accomplishes this nicely as it will prevent typos and allow for a drop down box of valid instruments. If anyone has a better solution, please post it here! Thanks

        Code:
         
        // In variables
        private InstrumentList instrumentA = InstrumentList.ES_12_11; // default instrument A
        private InstrumentList instrumentB = InstrumentList.ES_03_12; // default instrument B
         
        // Use an enum to force user to select a valid instrument (and avoid typos)
        public enum InstrumentList
        {
        ES_12_11,
        ES_03_12,
        ZW_12_11,
        ZW_03_12
        }
         
        // Method to convert enum to string representation
        public static string InstrumentToString(InstrumentList i)
          {
           string name = "";
           switch (i)
           {
            case InstrumentList.ES_12_11:
             name = "ES 12-11";
             break;
            case InstrumentList.ES_03_12:
             name = "ES 03-12";
             break;
            case InstrumentList.ZW_12_11:
             name = "ZW 12-11";
             break;
            case InstrumentList.ZW_03_12:
             name = "ZW 03-12";
             break;
           }
           return name;
          }
         
        // In initialize
        Add(InstrumentToString(instrumentA),PeriodType.Minute, 1);
        Add(InstrumentToString(instrumentB),PeriodType.Minute, 1);
         
        // In parameters
        [Description("Select Instrument A")]
          [GridCategory("Parameters")]
          public InstrumentList InstrumentA
          {
          get{return instrumentA;}
          set{instrumentA = value;}
          }
         
          [Description("Select Instrument B")]
          [GridCategory("Parameters")]
          public InstrumentList InstrumentB
          {
          get{return instrumentB;}
          set{instrumentB = value;}
          }

        Comment


          #5
          kcsystemtrader,

          If you import your symbols from a .csv file, you can use StreamReader or System.IO to read from it. Please find some helpful reference samples for using these features below. You can also do this with the exposed instrument list as Bertrand mentioned.

          StreamReader : http://www.ninjatrader.com/support/f...ead.php?t=3476

          System.IO : http://www.ninjatrader.com/support/f...ead.php?t=3477

          Please let me know if I may assist further.
          Last edited by NinjaTrader_AdamP; 11-04-2011, 02:41 PM.
          Adam P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by kcsystemtrader View Post
            Thanks. It seems to me that since NT already has the instruments list data and since these lists can be user defined, it would be nice if they were exposed for use by a strategy. Potential enhancement request.
            the instrumentlist is already exposed. search the forum, there are already codes relating to the same.

            Comment


              #7
              You are right...I must have missed this post when I searched previously...

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by esmall, Today, 07:14 PM
              0 responses
              3 views
              0 likes
              Last Post esmall
              by esmall
               
              Started by Option Whisperer, 05-09-2024, 07:58 PM
              6 responses
              26 views
              0 likes
              Last Post Option Whisperer  
              Started by rayyyu12, Today, 05:38 PM
              0 responses
              12 views
              0 likes
              Last Post rayyyu12  
              Started by xepher101, Yesterday, 12:19 PM
              2 responses
              30 views
              0 likes
              Last Post xepher101  
              Started by thumper57, Today, 04:30 PM
              0 responses
              8 views
              0 likes
              Last Post thumper57  
              Working...
              X