Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with Time array

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

    Problem with Time array

    Hello, I'm developing a new indicator and I need to acces the timestap of a bar in a method outside the OnBarUpdate method.

    When I access the Time array I get an exception because of the index is outside the dimension. I checked the size for the time array and I have the right size and the right value in the Count property, but when I check the value for CurrentBar it has -1 and when I try to access an element that should be in the array I get the exception.

    Any Idea about what can be happening?

    Thanks

    #2
    telbentel, unfortunately the Time[x] array only exists within the OnBarUpdate() context. You could update a time variable every OnBarUpdate() and then access that value from your method.
    Code:
    OnBarUpdate()
    {
       obuTime = Time[0];
       ...
    }
    SomeOtherMethod()
    {
       mostRecentBarTime = obuTime;
       ...
    }
    AustinNinjaTrader Customer Service

    Comment


      #3
      If I force a call to OnBarUpdate, would I have access to Time variable?

      I need to know the timestamp of the bar clicked, at the moment I can get the bar number, if after getting the bar number, I force a call to OnBarUpdate, and get the timestamp that would solve my problem. Is it possible?

      Comment


        #4
        telbentel, forcing calls and grabbing data from a mouse event is unfortunately unsupported, but that does not mean it isn't possible.
        AustinNinjaTrader Customer Service

        Comment


          #5
          ok, thaks a lot for your help

          Comment


            #6
            An Alternative.

            I wonder if it would be easier to maintain your own Time[] array that can be accessed outside of the OnBarUpdate() method.

            For Example if you declare your own DataTimeSeries array
            Code:
            [LEFT]#region Variables
            private DateTimeSeries myDateTimeSeries; // Define a DateTimeSeries variable
            #endregion[/LEFT]
             
            [LEFT]// Create a DateTimeSeries object and assign it to the variable
            protected override void Initialize() 
            {
               // MaximumBarsLookBack determines how many values the DateTimeSeries will have access to
               myDateTimeSeries = new DataSeries(this, MaximumBarsLookBack.Infinite);
            }[/LEFT]
            Then on each new bar set its value to the current TIME[] array value. eg:
            Code:
            [LEFT]protected override void OnBarUpdate()
            {
               // Store the current time
               myDateTimeSeries.Set(Time[0]);
            }[/LEFT]
            That way you could access the Time array directly without roundtriping to the OnBarUpdate each time.
            Last edited by David Lean; 05-21-2011, 08:03 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            574 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            332 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X