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

Set Instrument symbol and timeframe within the strategy code

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

    Set Instrument symbol and timeframe within the strategy code

    Hey,

    How can I instument symbol (ES) and timeframe (2000 tick) within the strategy code? Use may change it later, but it would predefined to ES 2000 tick.

    #2
    Hello UltraNIX,

    Thanks for your post.

    You could add an additional data series in your script using AddDataSeries(). Then, you could ignore processing logic for BarsInProgress 0 (primary series) and add all of your logic within BarsInProgress 1 (added data series). If all your strategy logic is within a BarsInProgress 1 check then your strategy's logic would only process for the added data series.

    See the help guide documentation below for more information AddDataSeries() and BarsInProgress.
    AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
    BarsInProgress: https://ninjatrader.com/support/help...inprogress.htm

    Let us know if we may assist further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Users have the pleasure of choosing whatever BarType and Instrument to
      run a strategy -- there is no 'default' setting for these -- users are forced to
      make these choices when starting the strategy.

      You can make efforts to defeat these choices, such as adding a new data
      series of your preferred instrument, and ignoring BarsInProgress == 0.

      Or, perhaps a better approach -- setup your strategy to inspect the user
      choices of BarType and Instrument, and refuse to run if these values are
      unacceptable.

      Comment


        #4
        Originally posted by NinjaTrader_BrandonH View Post
        Hello UltraNIX,

        Thanks for your post.

        You could add an additional data series in your script using AddDataSeries(). Then, you could ignore processing logic for BarsInProgress 0 (primary series) and add all of your logic within BarsInProgress 1 (added data series). If all your strategy logic is within a BarsInProgress 1 check then your strategy's logic would only process for the added data series.

        See the help guide documentation below for more information AddDataSeries() and BarsInProgress.
        AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
        BarsInProgress: https://ninjatrader.com/support/help...inprogress.htm

        Let us know if we may assist further.
        Adding additional data series would require me to refactor code (like, instead of using Time[0], I would have to use Times[1][0]), which seems unworthy of effort.

        NinjaTrader could have a thought of letting creator of a strategy to determine symbol and timeframe in later releases.

        Comment


          #5
          Originally posted by bltdavid View Post
          Users have the pleasure of choosing whatever BarType and Instrument to
          run a strategy -- there is no 'default' setting for these -- users are forced to
          make these choices when starting the strategy.

          You can make efforts to defeat these choices, such as adding a new data
          series of your preferred instrument, and ignoring BarsInProgress == 0.

          Or, perhaps a better approach -- setup your strategy to inspect the user
          choices of BarType and Instrument, and refuse to run if these values are
          unacceptable.
          Yes, I am leaning towards that approach - inspect and refuse, if values are unacceptable, if it's not possible to set symbol and timeframe.

          Comment


            #6
            Originally posted by UltraNIX View Post
            Adding additional data series would require me to refactor code (like, instead of using Time[0], I would have to use Times[1][0]), which seems unworthy of effort.
            Well, uh, hold on there a second. That is not necessarily the case.

            Let's consider BarsInProgress a bit more.

            When OnBarUpdate is called with BarsInProgress == 1, everything
            has been pre-set to what is known as the 'BarsInProgress context'.

            What does that mean?
            It means a reference like Time[0] automatically reflects the current
            BarsInProgress data series.

            Which means,
            You only need to use Times[1][0] if BarsInProgress != 1.

            The idea is when BIP=n, having to explicitly use Times[n][0] is not
            strictly necessary -- because Time[0], Close[0], etc, have all been
            mapped to the correct series for the current BIP
            .

            That is called the 'BarsInProgress context', and is an automatic
            internal setup before calling OnBarUpdate, OnMarketData, etc.

            Thus, in a simple case, perhaps all you need to do is put a guard
            to filter out all unwanted BarsInProgress values (including 0), so
            that your logic only applies to a certain data series,

            Code:
            protected override void OnBarUpdate()
            {
                if (BarsInProgress != 1)
                   return;
            
                ... use Time[0], Close[0], etc, normally ...
                ... all references are using BIP == 1 series ...
            }
            This cuts way down on any refactoring.

            See 'Accessing the Price Data in a Multi-Bars NinjaScript' here.
            Last edited by bltdavid; 07-12-2021, 10:42 AM. Reason: forgot 'void' return type in OnBarUpdate

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by algospoke, Yesterday, 06:40 PM
            2 responses
            23 views
            0 likes
            Last Post algospoke  
            Started by ghoul, Today, 06:02 PM
            3 responses
            15 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            46 views
            0 likes
            Last Post jeronymite  
            Started by Barry Milan, Yesterday, 10:35 PM
            7 responses
            23 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by AttiM, 02-14-2024, 05:20 PM
            10 responses
            181 views
            0 likes
            Last Post jeronymite  
            Working...
            X