Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question on DataSeries Class

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

    Question on DataSeries Class

    I see this example:

    protected override void OnBarUpdate()
    {
    // Calculate the range of the current bar and set the value
    myDataSeries.Set(High[0] - Low[0]);
    }

    Does this only initialize the current bar, and leave all the remaining bars not initialized?
    Shouldn't we use a for loop in Initialize() function to go through each historical bar and call DataSeries.Set(int barsAgo, double value)?

    #2
    zehua,

    OnBarUpdate() is called for each bar, including historical ones, so it updates the dataseries automatically with past information.

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the fast reply, Adam.
      This is hard to understand. When is this called to update on each bar? From the source code, I only see the most recent bar being set.

      Comment


        #4
        Originally posted by zehua View Post
        Thanks for the fast reply, Adam.
        This is hard to understand. When is this called to update on each bar? From the source code, I only see the most recent bar being set.
        It is an event handler, not a method. So it is called every time the event happens, which it does on every tick. So if using the COBC = true default setting, it will be triggered at the close of every bar.

        Comment


          #5
          Thanks, koganam. Yeah I know OnBarUpdate is an event handler. So you are saying this code example would only update values for the current bar, and for incoming bars, but bars in the past won't get initialized?
          When this strategy just starts, myDataSeries will only have the current bar value set, and all of the rest 255 values are null? Well, maybe I should just set a debugger break point to see it myself.

          Comment


            #6
            Originally posted by zehua View Post
            Thanks, koganam. Yeah I know OnBarUpdate is an event handler. So you are saying this code example would only update values for the current bar, and for incoming bars, but bars in the past won't get initialized?
            When this strategy just starts, myDataSeries will only have the current bar value set, and all of the rest 255 values are null? Well, maybe I should just set a debugger break point to see it myself.
            If you have not done any specific code handling for Historical bars, then there will be, (logically ), a BarUpdate event once on every historical bar, so values will be plotted. The smiley is because I also had a little trouble getting the hang of it when I started.
            Last edited by koganam; 03-04-2012, 12:44 PM. Reason: Corrected spacing

            Comment


              #7
              Aha. I now understand. So when the strategy starts, initialize() is called once and OnBarUpdate() is called 256 times for each of the past bars. Now I understand both this issue and how the custom indicator code works. Thanks a lot!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              61 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              40 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              21 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              23 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              51 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X