Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add instrument

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

    Add instrument

    Hi!
    I would like to add an instument depending on the current instrument. Add() is only possible in Initialize() but Instrument.MasterInstrument.Name() is not allowed in Initialize(). So how can I find out in Initialize() on what instrument I am working on?
    Thanks, DH

    #2
    Hello DH008,

    You can access this with Instrument.FullName


    You can also add an interval without specifying an instrument if you want the second series to match the primary.

    Add(PeriodType.Minute, 3);

    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hello RyanM,

      Instrument.FullName gives wrong results when used in the strategy analyzer:
      o start Strategy Analyzer
      o click on an instrument
      o click on Backtest
      -> Initialize() is on the wrong instrument
      Thanks, DH

      Comment


        #4
        Initialize is called across strategy instances so this property shouldn't be relied upon for the particular one your'e working with. Best is to access this from OnBarUpdate, and if you need the underlying series to match the primary, just don't specify an instrument during your Add() statements.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Well, I have a request from a client for a trading system. He needs to have the exchange rate from the transaction currency to Euro. For example, if the system runs on GBP/USD he needs EUR/GBP as secondary instrument.
          How do I do that?

          Comment


            #6
            DH008,

            Unfortunately it can't be added dynamically like this. What you may consider doing is adding the second series as a custom input.

            The string would be the custom input you add from the strategy wizard and then put in place of the instrument in the add series.

            Example:

            Code:
             
            #region Variables
            // Wizard generated variables
            private string myCustomInstrument = @""; // Default setting for MyCustomInstrument
            // User defined variables (add any user defined variables below)
            #endregion
             
            protected override void Initialize()
            {
            Add(MyCustomInstrument, PeriodType.Minute, 30);
            }
             
             
            #region Properties
            [Description("")]
            [GridCategory("Parameters")]
            public string MyCustomInstrument
            {
            get { return myCustomInstrument; }
            set { myCustomInstrument = value; }
            }
            #endregion
            There is also an undocumented / unsupported approach to this below:


            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              RyanM,
              thank you for your quick reply.

              It is not posible to ask my client to enter a currency pair manually, the system has to run fully automated. Also the undocumented approach is now way to go.

              It is very strange to run a trading system and on startup you don't even know on what instrument you are running on. Maybe you could change this with the next release.

              For a workarond is it possible to check:
              a) whether the strategy is running in real time on a chart or on the strategy analyser
              b) if an instrument exists befor I use the Add() function

              Or any othe rworkaround like calling Initialize() once in OnBarUpdate()?

              Thanks, DH

              Comment


                #8
                Unfortunately I'm not aware of a way to work around this.
                • Additional series must be hard-coded in Initialize method.
                • There's no supported way of calling this method within OnBarUpdate().
                • There's no supported way of identifying if the strategy is run on chart or strategy analyzer.
                I will forward your suggestion to our development team, that you'd like to identify the instrument the strategy is run against prior to Initialize().

                Edit:
                I thought of one additional approach you could take:

                Perhaps you could hard code all the EUR / * series in the Initialize() method and then access the Instrument name property from OnBarUpdate?
                Last edited by NinjaTrader_RyanM1; 06-28-2010, 12:34 PM.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_RyanM View Post
                  Edit:
                  I thought of one additional approach you could take:

                  Perhaps you could hard code all the EUR / * series in the Initialize() method and then access the Instrument name property from OnBarUpdate?
                  RyanM,
                  thanks for the tip but I don't like to hard code a lot of additional series because I think that would use a lot of CPU.

                  I found a similar workaround:
                  It seams when you start a stategie on a chart you get the right instrument in Initialize(). When you start a strategie on the strategie analyzer, Initialize() is called two times, first with some random instrument from the default list (a Future contract in my case) and a second time with the right instrument.

                  What I did is to create a hard coded list of "supported currencies". Now, whenever Initialize() is called with an instrument not in the list of supported currencies I just skip the part of adding an additional data series and print a warning to the output window.

                  This is just a workaround and I still have to explain this to my client. I hope in one of the next releases this issue can be solved.

                  Thank you for your help,
                  best regards,
                  DH

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  595 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
                  556 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  554 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X