Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting past int value

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

    Getting past int value

    I have
    Code:
    int = myCount
    myCount is a value that is assigned to a bar depending on different factors.

    I want to access and print out random past values of myCount. Lets say I want to see the value from bar #19 (assuming current bar is 0). How do I access it?

    #2
    At the top of your code in the variable declarations, add something like: private Series<int> MyCountSeries = null;

    In State.Configure or State.DataLoaded you'll do something like: MyCountSeries = new Series<int>(this);

    In OnBarUpdate (or wherever) you're setting myCount, right after that, do: MyCountSeries[0] = myCount;

    Then, later, you can use MyCountSeries[1] to get 1 bar back etc.

    A few other notes - you shouldn't (or can't) name your variable int like that because int is a keyword. I'm assuming instead of "int = myCount" you mean "int myCount" or "int myCount = something" or "int myCount; myCount = something".

    Also, if, as you say, current bar is 0, you can't get bar #19 because that is in the future. If what you mean is current bar is 0 BACK then bar 19 BACK is MyCountSeries[19].

    If you are using more than one data series, but this series is about the chart bars, you should check "if (CurrentBars[0] >= 0)" before you access MyCountSeries[0] because there might not be any chart bars yet.

    If you are exporting this series e.g. it's a vector output from an indicator that you need in a strategy, you should initialize it in State.Configure - otherwise, it should be in State.DataLoaded.

    If you need more than 256 bars of history, you can use the overload with MaximumBarsLookback.Infinite but this uses more resources so you should not do it unless you need more than 256 bars of history (an example would be if you are using it in OnRender, or need to look all the way back to the start of the series for some reason).
    Last edited by QuantKey_Bruce; 03-31-2023, 04:43 AM.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello, thanks for writing in. You can create a class level Series object. Series objects are arrays that have a slot index for every bar on the chart. Please see the example here:



      Kind regards,
      -ChrisL​
      Last edited by NinjaTrader_ChrisL; 03-31-2023, 07:48 AM. Reason: Fixed the link

      Comment


        #4
        Originally posted by NinjaTrader_ChrisL View Post
        Hello, thanks for writing in. You can create a class level Series object. Series objects are arrays that have a slot index for every bar on the chart. Please see the example here:

        https://ninjatrader.com/support/help...a_series_or_da taseries_o.htm

        Kind regards,
        -ChrisL​
        That link does not link.

        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Originally posted by QuantKey_Bruce View Post
          At the top of your code in the variable declarations, add something like: private Series<int> MyCountSeries = null;

          In State.Configure or State.DataLoaded you'll do something like: MyCountSeries = new Series<int>(this);

          In OnBarUpdate (or wherever) you're setting myCount, right after that, do: MyCountSeries[0] = myCount;

          Then, later, you can use MyCountSeries[1] to get 1 bar back etc.

          A few other notes - you shouldn't (or can't) name your variable int like that because int is a keyword. I'm assuming instead of "int = myCount" you mean "int myCount" or "int myCount = something" or "int myCount; myCount = something".

          Also, if, as you say, current bar is 0, you can't get bar #19 because that is in the future. If what you mean is current bar is 0 BACK then bar 19 BACK is MyCountSeries[19].

          If you are using more than one data series, but this series is about the chart bars, you should check "if (CurrentBars[0] >= 0)" before you access MyCountSeries[0] because there might not be any chart bars yet.

          If you are exporting this series e.g. it's a vector output from an indicator that you need in a strategy, you should initialize it in State.Configure - otherwise, it should be in State.DataLoaded.

          If you need more than 256 bars of history, you can use the overload with MaximumBarsLookback.Infinite but this uses more resources so you should not do it unless you need more than 256 bars of history (an example would be if you are using it in OnRender, or need to look all the way back to the start of the series for some reason).
          Works. Thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          46 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          66 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X