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:
    [COLOR=#0000ff][COLOR=#0000ff]public[/COLOR] [COLOR=#0000ff]class[/COLOR] [COLOR=#080808]kpTest1[/COLOR] : [COLOR=#080808]Indicator[/COLOR]
    {
    [COLOR=#0000ff]protected[/COLOR] [COLOR=#0000ff]override[/COLOR] [COLOR=#0000ff]void[/COLOR] [COLOR=#080808]OnStateChange[/COLOR]()
    {
    [COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]State[/COLOR] == [COLOR=#080808]State[/COLOR].[COLOR=#080808]SetDefaults[/COLOR])
    {
    [COLOR=#080808]Description[/COLOR] = [COLOR=#b22222]@"Enter the description for your new custom Indicator here."[/COLOR];
    [COLOR=#080808]Name[/COLOR] = [COLOR=#b22222]"kpTest1"[/COLOR];
    [COLOR=#080808]Calculate[/COLOR] = [COLOR=#080808]Calculate[/COLOR].[COLOR=#080808]OnBarClose[/COLOR];
    [COLOR=#080808]IsOverlay[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]DisplayInDataBox[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]DrawOnPricePanel[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]DrawHorizontalGridLines[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]DrawVerticalGridLines[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]PaintPriceMarkers[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]ScaleJustification[/COLOR] = [COLOR=#080808]NinjaTrader[/COLOR].[COLOR=#080808]Gui[/COLOR].[COLOR=#080808]Chart[/COLOR].[COLOR=#080808]ScaleJustification[/COLOR].[COLOR=#080808]Right[/COLOR];
    [COLOR=#006400]//Disable this property if your indicator requires custom values that cumulate with each new market data event. [/COLOR]
    [COLOR=#006400]//See Help Guide for additional information.[/COLOR]
    [COLOR=#080808]IsSuspendedWhileInactive[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    }
    [COLOR=#0000ff]else[/COLOR] [COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]State[/COLOR] == [COLOR=#080808]State[/COLOR].[COLOR=#080808]Configure[/COLOR])
    {
    [COLOR=#080808]AddDataSeries[/COLOR]([COLOR=#080808]Data[/COLOR].[COLOR=#080808]BarsPeriodType[/COLOR].[COLOR=#080808]Day[/COLOR], [COLOR=#ff8c00]1[/COLOR]); 
    }
    }
    [COLOR=#0000ff]protected[/COLOR] [COLOR=#0000ff]override[/COLOR] [COLOR=#0000ff]void[/COLOR] [COLOR=#080808]OnBarUpdate[/COLOR]()
    {
    [COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]BarsInProgress[/COLOR] > [COLOR=#ff8c00]0[/COLOR]) [COLOR=#080808]Print[/COLOR]([COLOR=#0000ff]string[/COLOR].[COLOR=#080808]Format[/COLOR]([COLOR=#b22222]"OnBarUpdate Time={0} State={1} CurrentBar={2} BarsInProgress={3}"[/COLOR], [COLOR=#080808]Time[/COLOR][[COLOR=#ff8c00]0[/COLOR]], [COLOR=#080808]State[/COLOR], [COLOR=#080808]CurrentBar[/COLOR], [COLOR=#080808]BarsInProgress[/COLOR])); 
    }
    }
    [/COLOR]
    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:
    [COLOR=#0000ff][COLOR=#0000ff]public[/COLOR] [COLOR=#0000ff]class[/COLOR] [COLOR=#080808]kpTest1[/COLOR] : [COLOR=#080808]Indicator[/COLOR]
    {
    [COLOR=#0000ff]protected[/COLOR] [COLOR=#0000ff]override[/COLOR] [COLOR=#0000ff]void[/COLOR] [COLOR=#080808]OnStateChange[/COLOR]()
    {
    [COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]State[/COLOR] == [COLOR=#080808]State[/COLOR].[COLOR=#080808]SetDefaults[/COLOR])
    {
    [COLOR=#080808]Description[/COLOR] = [COLOR=#b22222]@"Enter the description for your new custom Indicator here."[/COLOR];
    [COLOR=#080808]Name[/COLOR] = [COLOR=#b22222]"kpTest1"[/COLOR];
    [COLOR=#080808]Calculate[/COLOR] = [COLOR=#080808]Calculate[/COLOR].[COLOR=#080808]OnBarClose[/COLOR];
    [COLOR=#080808]IsOverlay[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]DisplayInDataBox[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]DrawOnPricePanel[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]DrawHorizontalGridLines[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]DrawVerticalGridLines[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]PaintPriceMarkers[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    [COLOR=#080808]ScaleJustification[/COLOR] = [COLOR=#080808]NinjaTrader[/COLOR].[COLOR=#080808]Gui[/COLOR].[COLOR=#080808]Chart[/COLOR].[COLOR=#080808]ScaleJustification[/COLOR].[COLOR=#080808]Right[/COLOR];
    [COLOR=#006400]//Disable this property if your indicator requires custom values that cumulate with each new market data event. [/COLOR]
    [COLOR=#006400]//See Help Guide for additional information.[/COLOR]
    [COLOR=#080808]IsSuspendedWhileInactive[/COLOR] = [COLOR=#0000ff]true[/COLOR];
    }
    [COLOR=#0000ff]else[/COLOR] [COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]State[/COLOR] == [COLOR=#080808]State[/COLOR].[COLOR=#080808]Configure[/COLOR])
    {
    [COLOR=#080808]AddDataSeries[/COLOR]([COLOR=#080808]Data[/COLOR].[COLOR=#080808]BarsPeriodType[/COLOR].[COLOR=#080808]Day[/COLOR], [COLOR=#ff8c00]1[/COLOR]); 
    }
    }
    [COLOR=#0000ff]protected[/COLOR] [COLOR=#0000ff]override[/COLOR] [COLOR=#0000ff]void[/COLOR] [COLOR=#080808]OnBarUpdate[/COLOR]()
    {
    [COLOR=#0000ff]if[/COLOR] ([COLOR=#080808]BarsInProgress[/COLOR] > [COLOR=#ff8c00]0[/COLOR]) [COLOR=#080808]Print[/COLOR]([COLOR=#0000ff]string[/COLOR].[COLOR=#080808]Format[/COLOR]([COLOR=#b22222]"OnBarUpdate Time={0} State={1} CurrentBar={2} BarsInProgress={3}"[/COLOR], [COLOR=#080808]Time[/COLOR][[COLOR=#ff8c00]0[/COLOR]], [COLOR=#080808]State[/COLOR], [COLOR=#080808]CurrentBar[/COLOR], [COLOR=#080808]BarsInProgress[/COLOR])); 
    }
    }
    [/COLOR]
    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.

        Jessica P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by jxs_xrj, 01-12-2020, 09:49 AM
        6 responses
        3,290 views
        1 like
        Last Post jgualdronc  
        Started by Touch-Ups, Today, 10:36 AM
        0 responses
        8 views
        0 likes
        Last Post Touch-Ups  
        Started by geddyisodin, 04-25-2024, 05:20 AM
        11 responses
        61 views
        0 likes
        Last Post halgo_boulder  
        Started by Option Whisperer, Today, 09:55 AM
        0 responses
        8 views
        0 likes
        Last Post Option Whisperer  
        Started by halgo_boulder, 04-20-2024, 08:44 AM
        2 responses
        24 views
        0 likes
        Last Post halgo_boulder  
        Working...
        X