Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate question

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

    OnBarUpdate question

    I have a strategy that Uses the VIX as its primary bars and the trades a few other instruments. I am connected to TD Ameritrade.

    code in on bar update:

    Code:
    [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] OnBarUpdate() {[/SIZE]
    [SIZE=2]Print([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Format([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"{0},{1},this.Historical={2}"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], Time[0], Instrument.FullName, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]this[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Historical));[/SIZE]
    [SIZE=2]}[/SIZE]
    Output:

    4/19/2011 1:00:00 PM,^VIX,this.Historical=True
    4/19/2011 1:00:00 PM,DIA,this.Historical=True
    4/19/2011 1:00:00 PM,EEM,this.Historical=True

    4/20/2011 1:00:00 PM,^VIX,this.Historical=True
    4/20/2011 1:00:00 PM,DIA,this.Historical=True
    4/20/2011 1:00:00 PM,EEM,this.Historical=True

    4/21/2011 1:00:00 PM,EEM,this.Historical=False
    4/21/2011 1:00:00 PM,DIA,this.Historical=False

    I am not sure why I did not get a print statement for the VIX for 4/21 today is 4/25? When should I expect the VIX OnBarUpdate to fire?

    Thanks,
    Erik

    #2
    Hello Erik,

    Thanks for the post. It depends on the time stamp of each series relative to the other series. You won't receive an update in advance of the other series.

    The bar referencing model for multiseries is explained here, which will vary based on real time or historical: See the section: How Bar Data is Referenced


    What does a chart of ^Vix look like?
    What intervals have you added?
    What is the primary series?
    What is the session template defined for VIX in the instrument manager?
    Are you accessing this historically or real time?
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      The VIX Chart shows the 21st (first mage below)

      VIX is the primary bar series (Daily) and I added 2 other Daily ETFs.

      VIX is configured as US Equities RTH (second image below).

      Not sure how to answer this one:
      Are you accessing this historically or real time?
      I have a strategy that I expect to get some info from the VIX (OnBarUpdate) and use it in my logic when I get (OnBarUpdate) for my other symbols. The strategy has been backtested using IQFeed connections.

      So, I am not sure what needs to be done differently to get the OnBarUpdate to fire from the output on the previous post it seems that it fires for historical bars, but not real-time. Only the other 2 instruments get the OnBarUpdate event.

      4/21/2011 1:00:00 PM,EEM,this.Historical=False
      4/21/2011 1:00:00 PM,DIA,this.Historical=False

      Thanks,
      Erik
      Attached Files

      Comment


        #4
        Also,
        I disabled my strategy and then opned Historical Data Manager on the edit tab I deleted ^VIX data.
        Then re enabled my strategy and this is what I get:

        Code:
        [COLOR=#0000ff]protected[SIZE=2][SIZE=2]override[/SIZE][/SIZE][/COLOR][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] OnBarUpdate() {[/SIZE]
        [SIZE=2]Print([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Format([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"{0},{1},this.Historical={2}"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], Time[0], Instrument.FullName, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]this[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Historical));[/SIZE]
        [SIZE=2]}[/SIZE]
        4/20/2011 1:00:00 PM,^VIX,this.Historical=True
        4/20/2011 1:00:00 PM,DIA,this.Historical=True
        4/20/2011 1:00:00 PM,EEM,this.Historical=True

        4/21/2011 1:00:00 PM,^VIX,this.Historical=True
        4/21/2011 1:00:00 PM,DIA,this.Historical=True
        4/21/2011 1:00:00 PM,EEM,this.Historical=True

        The VIX shows up as a historical bar for the 21st.

        I will leave the strategy running and see if I get the OnBarUpdate tomorrow or not for a new day that is not Historical.

        Not sure if it matters, but I am in Arizona.

        Thanks,
        Erik

        Comment


          #5
          Hi Erik,

          If you're working with a daily bar in an historical context, you should be aware of the time stamp of the bar, defined by the session template. You are not able to access the daily bar in advance (based on time stamp) of the other series.

          The session template that is used depends on whether VIX is applied to the chart or not.

          If a multi-series script adds an additional Bars object that already exists on the chart, the script will use the preexisting series instead of creating a new one to conserve memory. This includes that series' session template as applied from the chart. If the Bars object does not exist on the chart, the session template of the added Bars object will be the session template of the primary Bars object. If the primary Bars object is using the "<Use instrument settings>" session template then the additional Bars objects will use the default session templates as defined for their particular instruments in the Instrument Manager.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            I shut down NinjaTrader and restarted it (nothing in memory now). No charts open.

            File menus “Global Simulation Mode” is not checked (should be ready to connect and run strategy live).

            I connected to TD Ameritrade and then from the Strategies tab right clicked and choose “New Strategy”. This is my strategy:

            Code:
            [COLOR=blue][FONT=Courier New]namespace[/FONT][/COLOR][FONT=Courier New][COLOR=#000000] NinjaTrader.Strategy {[/COLOR][/FONT]
            [FONT=Courier New][COLOR=blue]public[/COLOR][COLOR=blue]class[/COLOR][COLOR=#2b91af]Test3[/COLOR][COLOR=#000000] : [/COLOR][COLOR=#2b91af]Strategy[/COLOR][COLOR=#000000] {[/COLOR][/FONT]
            [FONT=Courier New][COLOR=blue]private[/COLOR][COLOR=blue]string[/COLOR][COLOR=#000000] instramentsList = [/COLOR][COLOR=#a31515]"DIA,EEM"[/COLOR][COLOR=#000000];[/COLOR][/FONT]
            [FONT=Courier New][COLOR=blue]protected[/COLOR][COLOR=blue]override[/COLOR][COLOR=blue]void[/COLOR][COLOR=#000000] Initialize() {[/COLOR][/FONT]
            [FONT=Courier New][COLOR=blue]string[/COLOR][COLOR=#000000][] InstList = instramentsList.Split([/COLOR][COLOR=#a31515]','[/COLOR][COLOR=#000000]);[/COLOR][/FONT]
            [FONT=Courier New][COLOR=blue]for[/COLOR][COLOR=#000000] ([/COLOR][COLOR=blue]int[/COLOR][COLOR=#000000] i = 0; i < InstList.Length; i++) {[/COLOR][/FONT]
            [FONT=Courier New][COLOR=#000000]                          Add(InstList[i], [/COLOR][COLOR=#2b91af]PeriodType[/COLOR][COLOR=#000000].Day, 1);[/COLOR][/FONT]
            [FONT=Courier New][COLOR=#000000]                    }[/COLOR][/FONT]
            [FONT=Courier New][COLOR=#000000]                    BarsRequired = 5;[/COLOR][/FONT]
            [FONT=Courier New][COLOR=#000000]                    SessionData = [/COLOR][COLOR=#a31515]"US Equities RTH"[/COLOR][COLOR=#000000];[/COLOR][/FONT]
            [FONT=Courier New][COLOR=#000000]                    CalculateOnBarClose = [/COLOR][COLOR=blue]true[/COLOR][COLOR=#000000];[/COLOR][/FONT]
            [FONT=Courier New][COLOR=#000000]        }[/COLOR][/FONT]
            [FONT=Courier New][COLOR=blue]protected[/COLOR][COLOR=blue]override[/COLOR][COLOR=blue]void[/COLOR][COLOR=#000000] OnBarUpdate() {[/COLOR][/FONT]
            [FONT=Courier New][COLOR=#000000]                    Print([/COLOR][COLOR=blue]string[/COLOR][COLOR=#000000].Format([/COLOR][COLOR=#a31515]"{0}, {1}, this.Historical={2}, Now={3}"[/COLOR][COLOR=#000000], Time[0], Instrument.FullName, [/COLOR][COLOR=blue]this[/COLOR][COLOR=#000000].Historical, [/COLOR][COLOR=#2b91af]DateTime[/COLOR][COLOR=#000000].Now));[/COLOR][/FONT]
            [FONT=Courier New][COLOR=#000000]        }[/COLOR][/FONT]
            [FONT=Courier New][COLOR=#000000]  }[/COLOR][/FONT]
            [FONT=Courier New][COLOR=#000000]}[/COLOR][/FONT]

            I checked the enabled box. This is the output from starting it:

            **NT** Enabling NinjaScript strategy 'Test3/ee9b6b849f5c4064aadf976c81a1c72a' : On starting a real-time strategy - StrategySync=SubmitImmediately SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=False MaxRestarts=4 in 5 minutes
            4/12/2011 1:00:00 PM, ^VIX, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/13/2011 1:00:00 PM, ^VIX, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/13/2011 1:00:00 PM, DIA, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/13/2011 1:00:00 PM, EEM, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/14/2011 1:00:00 PM, ^VIX, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/14/2011 1:00:00 PM, DIA, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/14/2011 1:00:00 PM, EEM, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/15/2011 1:00:00 PM, ^VIX, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/15/2011 1:00:00 PM, DIA, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/15/2011 1:00:00 PM, EEM, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/18/2011 1:00:00 PM, ^VIX, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/18/2011 1:00:00 PM, DIA, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/18/2011 1:00:00 PM, EEM, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/19/2011 1:00:00 PM, ^VIX, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/19/2011 1:00:00 PM, DIA, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/19/2011 1:00:00 PM, EEM, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/20/2011 1:00:00 PM, ^VIX, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/20/2011 1:00:00 PM, DIA, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/20/2011 1:00:00 PM, EEM, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/21/2011 1:00:00 PM, ^VIX, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/21/2011 1:00:00 PM, DIA, this.Historical=True, Now=4/25/2011 4:21:55 PM
            4/21/2011 1:00:00 PM, EEM, this.Historical=True, Now=4/25/2011 4:21:55 PM

            After the open this is the additional output:

            4/25/2011 1:00:00 PM, EEM, this.Historical=False, Now=4/26/2011 6:30:00 AM
            4/25/2011 1:00:00 PM, DIA, this.Historical=False, Now=4/26/2011 6:30:00 AM

            The ^VIX OnBarUpdate does not get called?

            Thanks,
            Erik

            Comment


              #7
              Hi Erik,

              We checked on our TDA account here and it doesn't look like they supply live index data, only historical. OnBarUpdate() won't fire if they aren't sending the data. Maybe check if they have an ETF equivalent for these which will update in real time.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Ok, Thanks I will switch to an ETF.

                What do I have to do to get the Level II screen working against TD Ameritrade? Is that something I need to talk to them about? Should TD Amaritrade Level II work in NT7?

                Comment


                  #9
                  Yes, it looks like it's offered for NASDAQ, but may need to be setup on your account.
                  Ryan M.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by judysamnt7, 03-13-2023, 09:11 AM
                  4 responses
                  53 views
                  0 likes
                  Last Post DynamicTest  
                  Started by ScottWalsh, Today, 06:52 PM
                  4 responses
                  33 views
                  0 likes
                  Last Post ScottWalsh  
                  Started by olisav57, Today, 07:39 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post olisav57  
                  Started by trilliantrader, Today, 03:01 PM
                  2 responses
                  19 views
                  0 likes
                  Last Post helpwanted  
                  Started by cre8able, Today, 07:24 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post cre8able  
                  Working...
                  X