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

Twice through OnBarUpdate()?

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

    Twice through OnBarUpdate()?

    Is there a way to have OnBarUpate() be called twice? My strategy really needs two iterations to be effective. Thanks in advance for the answer. -Dean

    #2
    Not being an under the Ninja hood guru all I can say is, I doubt it.

    However...

    there are plenty of ways to run your code twice within a single call to OnBarUpdate().

    for(int i = 0; i < 2; i++)
    {
    your code here
    }

    You gain an advantage of knowing what pass you are ont hrough your code by checking the value of i being 0 for the first pass or 1 for the second. Or if you want to make it simplier on the noggin you can set i = 1 and i < 3 for parameters and check i = 1 or i=2 for whcih pass.

    You could also put your code in a function and just call that twice.

    or a few other ways.

    So, I doubt you'll get two unique calls to OnBarUpdate() but that doesn't mean you can't run your code twice.

    Comment


      #3
      Originally posted by Newshues View Post
      Not being an under the Ninja hood guru all I can say is, I doubt it.

      However...

      there are plenty of ways to run your code twice within a single call to OnBarUpdate().

      for(int i = 0; i < 2; i++)
      {
      your code here
      }
      Sure I could do that, but that won't work in my case. I need the 2nd time through to know how many total bars there are, or iow what the rightmost (most recent) bar number is on the 2nd time through. I asked this question last weekend in a different way, but I'm still searching for a better answer.

      Comment


        #4
        try
        {
        junk = SMA(counter);
        counter++;
        }

        catch
        {
        TotalBars = counter - 1;
        }

        that's not the exact way to do it but there is an example of try-catch blocks over in the reference section.

        You'd also have to include some kind of check to ensure the current bars time is equal to the current time before processing anything.

        and I doubt it will ever be exact.

        Comment


          #5
          Originally posted by cybertunerone View Post
          Sure I could do that, but that won't work in my case. I need the 2nd time through to know how many total bars there are, or iow what the rightmost (most recent) bar number is on the 2nd time through. I asked this question last weekend in a different way, but I'm still searching for a better answer.
          I am not sure what are you trying to achieve, but it does not really matter how many times you run your code snipet in OnBarUpdate, since it will return the same bar number everytime.
          If you really need the last (current in the realtime) bar number,I suggest using:
          if(!Historical) Print(CurrentBar.ToString()); //or do your other stuff

          You can set CalculateOnBarClose to false to get the last "live" bar number
          Last edited by roonius; 02-08-2009, 02:54 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by ETFVoyageur, Today, 04:00 PM
          0 responses
          5 views
          0 likes
          Last Post ETFVoyageur  
          Started by AaronKTradingForum, Today, 03:44 PM
          1 response
          6 views
          0 likes
          Last Post AaronKTradingForum  
          Started by Felix Reichert, 04-26-2024, 02:12 PM
          11 responses
          77 views
          0 likes
          Last Post Felix Reichert  
          Started by junkone, 04-28-2024, 02:19 PM
          7 responses
          82 views
          1 like
          Last Post junkone
          by junkone
           
          Started by pechtri, 06-22-2023, 02:31 AM
          11 responses
          136 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Working...
          X