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

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 GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,229 views
            0 likes
            Last Post xiinteractive  
            Started by andrewtrades, Today, 04:57 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            7 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            441 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            12 views
            0 likes
            Last Post FAQtrader  
            Working...
            X