Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get current symbol

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

    How to get current symbol

    Is it possible to get the current symbol when in a multi-time strategy?

    What I actually want to do is hard code my parameters in the code for each of the symbols I trade, that way I don't have to enter them in the parameters each time I run a strategy. But I'm not sure how to find out which symbol the strategy is running with.

    EDIT:

    I just found this:

    Print("Instrument.MasterInstrument.Name=" + Instrument.MasterInstrument.Name);

    I put it in initialize and I backtest a strategy. This is odd, it prints:

    Instrument.MasterInstrument.Name=ES
    Instrument.MasterInstrument.Name=ES
    Instrument.MasterInstrument.Name=NQ

    I'm running my strategy against NQ. Why would it print ES twice?
    Last edited by cunparis; 12-01-2008, 10:38 AM.

    #2
    If it prints twice it means you fired OnBarUpdate() for the ES twice before the NQ. This is completely possible since the data streams are independent of each other and will fire in whichever order the events are received.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      If it prints twice it means you fired OnBarUpdate() for the ES twice before the NQ. This is completely possible since the data streams are independent of each other and will fire in whichever order the events are received.
      I put the code in initialize. My strategy isn't multi-instrument and I'm only running it for NQ.

      When I put the print before my enterLong, it only prints on NQ so at least I know that only NQ is being traded. But I'm still not sure why it prints ES twice when I run NQ..

      Comment


        #4
        You should not put these prints from Initialize(). You cannot guarantee Initialize() only triggers once and the behavior of it. As such all logic should never be placed in Initialize() either.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          You should not put these prints from Initialize(). You cannot guarantee Initialize() only triggers once and the behavior of it. As such all logic should never be placed in Initialize() either.
          If I have code that needs to be executed one time only, where can I put it?

          Comment


            #6
            Code:
            if (CurrentBar == 0)
            {
                 // Do something'
            }
            In the top of OnBarUpdate().

            In a strategy, because min bars required= 20, you will need to use if (CurrentBar == 20) to run this calculation instead.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              cunparis,

              I've seen the strategy analyzer be very odd in that sense. It regularly executes Initialize() with a symbol from the default instrument list... something like ES, which I've never intentionally used. It does this when I click around, at the beginning/end of a backtest for an instrument list, etc.

              Comment


                #8
                Originally posted by heech View Post
                cunparis,

                I've seen the strategy analyzer be very odd in that sense. It regularly executes Initialize() with a symbol from the default instrument list... something like ES, which I've never intentionally used. It does this when I click around, at the beginning/end of a backtest for an instrument list, etc.
                Ok this explains why I'm seeing it, hopefully Ninjatrader can look into why it happens & does it really need to.

                Thanks for sharing your experience.

                The currentbar == 20 is ok but if one changes the min bar setting then it may break so I hesitate to put that in the code. It'd be nice if the code could have access to all the configuration parameters in the strategy window.

                Comment


                  #9
                  cunparis,

                  The Initialize() method is not designed for you to use to set any custom variable values or run any logic. You should never run anything from there besides setting of strategy defaults.

                  Not sure what you mean configuration parameters. The strategy does have access to all user defined parameters in the strategy window. You don't create these from the Initialize().

                  If you are worried about min bars required just do if (CurrentBar == BarsRequired).
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Josh View Post
                    If you are worried about min bars required just do if (CurrentBar == BarsRequired).
                    Perfect! This will work for me. Thank you for your help.

                    Comment

                    Latest Posts

                    Collapse

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