• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate firing out of sequence ?

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

    OnBarUpdate firing out of sequence ?

    I have an indicator (see code below) on a 1 minute chart on YM. The indicator adds a 1 day data series of the primary series. Data feed is IQFeed.

    Trading hours for the primary instrument is CME US Index Futures ETH and this is occurring after the close of RTH.

    I get the debug output below. Why is the CurrentBar 3 datetime stamp later than the datetime stamp of CurrentBar 4 ?

    OnBarUpdate Time=9/22/2016 5:00:00 PM State=Historical CurrentBar=0 BarsInProgress=1
    OnBarUpdate Time=9/23/2016 5:00:00 PM State=Historical CurrentBar=1 BarsInProgress=1
    OnBarUpdate Time=9/26/2016 5:00:00 PM State=Historical CurrentBar=2 BarsInProgress=1
    OnBarUpdate Time=9/28/2016 5:00:00 PM State=Historical CurrentBar=3 BarsInProgress=1
    OnBarUpdate Time=9/27/2016 5:00:00 PM State=Historical CurrentBar=4 BarsInProgress=1



    Code:
    public class kpTest1 : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "kpTest1";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Day, 1); 
    }
    }
    protected override void OnBarUpdate()
    {
    if (BarsInProgress > 0) Print(string.Format("OnBarUpdate Time={0} State={1} CurrentBar={2} BarsInProgress={3}", Time[0], State, CurrentBar, BarsInProgress)); 
    }
    }
    
    Last edited by hemlock; 09-27-2016, 06:17 PM.

    #2
    Originally posted by hemlock View Post
    I have an indicator (see code below) on a 1 minute chart on YM. The indicator adds a 1 day data series of the primary series. Data feed is IQFeed.

    Trading hours for the primary instrument is CME US Index Futures ETH and this is occurring after the close of RTH.

    I get the debug output below. Why is the CurrentBar 3 datetime stamp later than the datetime stamp of CurrentBar 4 ?

    OnBarUpdate Time=9/22/2016 5:00:00 PM State=Historical CurrentBar=0 BarsInProgress=1
    OnBarUpdate Time=9/23/2016 5:00:00 PM State=Historical CurrentBar=1 BarsInProgress=1
    OnBarUpdate Time=9/26/2016 5:00:00 PM State=Historical CurrentBar=2 BarsInProgress=1
    OnBarUpdate Time=9/28/2016 5:00:00 PM State=Historical CurrentBar=3 BarsInProgress=1
    OnBarUpdate Time=9/27/2016 5:00:00 PM State=Historical CurrentBar=4 BarsInProgress=1



    Code:
    public class kpTest1 : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "kpTest1";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Day, 1); 
    }
    }
    protected override void OnBarUpdate()
    {
    if (BarsInProgress > 0) Print(string.Format("OnBarUpdate Time={0} State={1} CurrentBar={2} BarsInProgress={3}", Time[0], State, CurrentBar, BarsInProgress)); 
    }
    }
    
    I noticed that a while back when I was getting unexpected trade action as I was generating the signal on the higher timeframe, and executing the trades on the faster timeframe. You are going to have to code around it. The order in which the ticks arrive in OnBarUpdate() is not guaranteed. It is just the way it is.

    Comment


      #3
      Thanks Osikani.

      What is really odd, and I just realized this, is the OnBarUpdate is reporting a bar on the 28th and it was still the 27th when the script was running. It wasn't even the 28th yet...

      After a reboot and a restart of Ninja the script is now reporting this on the 28th:

      OnBarUpdate Time=9/23/2016 5:00:00 PM State=Historical CurrentBar=0 BarsInProgress=1
      OnBarUpdate Time=9/26/2016 5:00:00 PM State=Historical CurrentBar=1 BarsInProgress=1
      OnBarUpdate Time=9/27/2016 5:00:00 PM State=Historical CurrentBar=2 BarsInProgress=1
      Last edited by hemlock; 09-27-2016, 11:01 PM.

      Comment


        #4
        Since I believe these two threads are related, I would like to redirect the community's attention to this thread.

        http://ninjatrader.com/support/forum...713#post476713
        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by priceisking, Today, 01:15 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by 2sureshk, Today, 07:29 AM
        1 response
        16 views
        0 likes
        Last Post NinjaTrader_Kate  
        Started by frayrengytrader, Today, 10:58 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_SergeyS  
        Started by levikNT, Today, 11:28 AM
        3 responses
        27 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by ballboy11, Today, 09:35 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X