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

BarsAgo appears to be lagging

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

    BarsAgo appears to be lagging

    Hello,

    As soon (i.e. immediately) as a new bar opens, I am needing to start scanning the prior bars.

    I must have something wrong because it looks to me like on the first tick of a new bar that the [0] bar pointer has not yet been moved to the new bar.

    Below is the code to indicate what is happening, if you put it in an indicator, on a new bar [0] is still pointing to what I would have thought would now be [1].

    (If you run it on a tick chart it will move fast enough to see what is happening.)

    Is this so?

    If possible, how can I reliably start processing backwards on the first tick of a new bar?

    Do I need to treat [0] as [1]?

    If so at what point does [0] move to the current bar, making that process invalid?

    Thank you.

    ================================================


    // This method is used to configure the indicator and is called once before any bar data is loaded.
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    Overlay = true;
    AutoScale = false;
    }

    /// Called on each bar update event (incoming tick)
    protected override void OnBarUpdate()
    {

    Print ("--------------------------------------------");
    Print ("New Bar");

    Print("Bar 0 Open = "+Open[0].ToString());
    DrawArrowDown("tag1", true, 0, Open[0] + TickSize, Color.Red);

    if (CurrentBar < 1)
    return;

    Print("Bar 1 Open = "+Open[1].ToString());
    DrawArrowDown("tag2", true, 1, Open[1] + TickSize, Color.Blue);

    }

    #2
    Hi Turtle Trader,

    This is the nature of how CalculateOnBarClose = true; behaves.
    More info at - http://www.ninjatrader-support.com/H...ateOnBarClose1

    If you want the logic to calculate [0] as the current bar, use CalculateOnBarClose = false;

    Alternatively, you can separate logic to calculate partially with COBC = false, and another part to only calculate once per bar.
    See this sample - http://www.ninjatrader.com/support/f...ad.php?t=19387
    TimNinjaTrader Customer Service

    Comment


      #3
      reply

      Thank you.

      It looks like what I need to do is set COBC = false and use the boolean FirstTickofBar.

      Comment


        #4
        Hi Turtle Trader,

        Great, glad to hear you are up and running.
        TimNinjaTrader Customer Service

        Comment


          #5
          reply

          Yes, it is working perfectly now.

          Thanks again.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by f.saeidi, Today, 01:32 PM
          2 responses
          4 views
          0 likes
          Last Post f.saeidi  
          Started by alifarahani, 04-19-2024, 09:40 AM
          9 responses
          55 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by mmckinnm, Today, 01:34 PM
          2 responses
          5 views
          0 likes
          Last Post mmckinnm  
          Started by Conceptzx, 10-11-2022, 06:38 AM
          3 responses
          60 views
          0 likes
          Last Post NinjaTrader_SeanH  
          Started by traderqz, Today, 12:06 AM
          9 responses
          16 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X