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

Two Pass Scanning of Data - Possible?

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

    #16
    Ralph, that's it!

    Now I can do what I need to do.

    Thanks a lot for your time and help.

    Comment


      #17
      There are many ways you could try to tackle this issue. (& possibly optimise your algorithm)
      Q1. Do I need to completely recalculate everything on every new bar / tick. If no, create a Boolean var, declare it as false. Set it to true the first time OnBarUpdate is called & you've completed your 1st pass.

      2. CurrentBar is a variable that tells you the number of bars in the series. The Leftmost bar in the chart (when you scroll all the way to the left = 1 (or 0 I can't recall)) The most recent bar is "N" which also = the total number of bars in the series. Note: This is exactly the opposite of Close[0] notation, where the rightmost bar = 0 & the very first bar is Close[N].

      3. The DataSeries is an array of Double, If you'd prefer another datatype there are quite a few others like IntSeries & similar. As Josh mentioned if you don't want the overhead of their iDataSeries Collections then just create your own array or collection. The disadvantage of that is you will have to manage the growth yourself. Whereas the Ninja collections will always have the correct number of bars.

      As Josh mentioned you can index, set, read a value from part of the collection. just use code similar to
      for( int = 1; int <= CurrentBar; i++ ) {
      if (i < 0) or i> CurrentBar) continue;
      mySeries[i] = mySeries[i-1]
      }
      Optimise:
      Perhaps you only need to go back N bars. Redoing this Order N squared algorithm on every bar (or every tick) will really hammer your CPU. & may impact perf if you are trading realtime.

      Optimiste 2:
      Create 2 dataseries. If the firstpass always generates the same initial values. Put the first pass in one dataseries (which you only need to update the newest bar once it is complete, & then use its values to completely recalc the 2ndPassDataSeries.

      Note: if you change the value of CalculateOnBarClose you get one extra bar in the series. So be very careful to check your code for boundary conditions. If doesn't like negative indexes.
      To ensure this doesn't hurt me I never set CalculateOnBarClose in my initialisation() routine. Leave it as a parameter set by the user or you risk weird bugs.

      I hope this gets you going.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by r68cervera, Today, 05:29 AM
      0 responses
      3 views
      0 likes
      Last Post r68cervera  
      Started by geddyisodin, Today, 05:20 AM
      0 responses
      6 views
      0 likes
      Last Post geddyisodin  
      Started by JonesJoker, 04-22-2024, 12:23 PM
      6 responses
      35 views
      0 likes
      Last Post JonesJoker  
      Started by GussJ, 03-04-2020, 03:11 PM
      12 responses
      3,241 views
      0 likes
      Last Post Leafcutter  
      Started by AveryFlynn, Today, 04:57 AM
      0 responses
      7 views
      0 likes
      Last Post AveryFlynn  
      Working...
      X