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

CalculateOnBarClose and variable persistence

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

    CalculateOnBarClose and variable persistence

    I have some indicators that work fine when they calculate on bar close but screw up when CalculateOnBarClose=false.

    The reason seems to be because I am expecting everything to be reset to their values on the previous bar on every call to OnBarUpdate(). This seems to be a bad assumption. So I ask for clarification: Any variables declared in the "variables" region, outside the scope of OnBarUpdate(), will have their values persist in each call to OnBarUpdate(), right? Does the same hold true for the latest DataSeries values set?

    Is there some way to have my indicator variables reset to the state they were in at the close of the last bar, so that these values can be used for intraday calculations? Or do I have to declare everything as DataSeries and access myvalue[1] all the time? That seems terribly memory-inefficient, unless there's some way to create 2-bar DataSeries.

    The only alternative I can think of is to maintain copies of all variables with their values from the previous bar, and whenever FirstTickOfBar() occurs, to update these copies. That gets kind of messy if I have a lot of variables, though.

    -A
    Last edited by anachronist; 06-07-2011, 06:59 PM.

    #2
    anachronist, you're correct in understanding that the COBC = false behaviour of your studies will need special attention, best would be to store the temp value needed in a variable so you would not have to run DataSeries objects for those calculations then.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks, that's what I thought.

      Is there a way to create DataSeries objects of lengths other than 256 or infinite? I couldn't find documentation about that, and when I tried it I got an error.

      Often I just need the most recent dozen or so values, and don't care about the older ones. In the case above I'd need a 2-value series.

      -A

      Comment


        #4
        Unfortunately this is not possible, so either infinite like 6.5 or 256 newly introduced for NT7. Best might just stored the values in double variables for your reference.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by anachronist View Post
          Thanks, that's what I thought.

          Is there a way to create DataSeries objects of lengths other than 256 or infinite? I couldn't find documentation about that, and when I tried it I got an error.

          Often I just need the most recent dozen or so values, and don't care about the older ones. In the case above I'd need a 2-value series.

          -A
          Why not just use an ArrayList then, removing at 0 and adding to the end of the array as you go along, so as to keep the ArrayList a fixed size.

          Comment


            #6
            Originally posted by koganam View Post
            Why not just use an ArrayList then, removing at 0 and adding to the end of the array as you go along, so as to keep the ArrayList a fixed size.
            I ended up doing something like that, only just using two variables. For example, if a0 is the current bar variable that gets changed on every tick, and a1 is the value to which it should be reset on each call to OnBarUpdate, I used
            PHP Code:
            if (FirstTickOfBar) { // save last values
               
            a1 a0;
               
            b1 b0;
               
            etc...
            } else { 
            // reset to last values
               
            a0 a1;
               
            b0 b1;
               
            etc...

            Then I just use a0, b0, and others in my code as I normally would.
            -A

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            11 responses
            38 views
            0 likes
            Last Post cmtjoancolmenero  
            Started by FrazMann, Today, 11:21 AM
            0 responses
            3 views
            0 likes
            Last Post FrazMann  
            Started by geddyisodin, Yesterday, 05:20 AM
            8 responses
            52 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by DayTradingDEMON, Today, 09:28 AM
            4 responses
            24 views
            0 likes
            Last Post DayTradingDEMON  
            Started by George21, Today, 10:07 AM
            1 response
            21 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Working...
            X