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 Aviram Y, Today, 05:29 AM
              0 responses
              2 views
              0 likes
              Last Post Aviram Y  
              Started by quantismo, 04-17-2024, 05:13 PM
              3 responses
              25 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by ScottWalsh, 04-16-2024, 04:29 PM
              7 responses
              34 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by cls71, Today, 04:45 AM
              0 responses
              6 views
              0 likes
              Last Post cls71
              by cls71
               
              Started by mjairg, 07-20-2023, 11:57 PM
              3 responses
              217 views
              1 like
              Last Post PaulMohn  
              Working...
              X