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 CarlTrading, 03-31-2026, 09:41 PM
            1 response
            152 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            89 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            133 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            127 views
            1 like
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            107 views
            0 likes
            Last Post CarlTrading  
            Working...
            X