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

OnBarUpdate for several stocks w/ Calculate OnBarClose is slow

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

    OnBarUpdate for several stocks w/ Calculate OnBarClose is slow

    I'm having an odd issue, where it looks like OnBarUpdate kind of trickles in the updates on live data for stocks when I am subscribed to several of them at the same time. Calculate is set to OnBarClose, so I would expect that as soon as the my minute bar closes, it will just take all the data from the last minute and quickly update my chart. When I load up a historical chart, it works quickly as I expect, but on live data it seems like OnBarUpdate doesn't occur quickly.

    What is going on behind the scenes, when Calculate.OnBarClose is set to true when many secondary series are added to a chart?

    #2
    Hello habibalex,

    Thank you for the post.

    Based on your expectation I believe this may be where the problem lies. In general OnBarUpdate would only get called when you are receiving market data, if that data happens to be the first tick of the next bar you would see the bar close and the next bar generate. If there was no data or ticks at this time that could make a slowly updating chart, this can be caused by low volume of an instrument.

    Could you provide an example of the setup you are currently using for me to see if this is the case or if something else is happening? I would like to try the same test you are to understand better how you are comparing the frequency of OnBarUpdate.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      For example, SPY and PCLN have a very different frequency of trades. OnBarUpdate is called almost immediately for every SPY bar, but PCLN is called maybe half the time. If I want to get the last bar of data in PCLN, and I use the GetBar function based on the CurrentBar based on the SPY bar, will that give me the correct data based on the last completed minuter?

      What would be the correct way of getting the last completed minute bar of data on PCLN if no trades had occurred? Im calculating a moving avg, so if it the stock price doesn't move, but time has passed, the moving average still should update.

      Comment


        #4
        Hello habibalex,

        Yes this is certainly normal to see two instruments OnBarUpdate happening at different rates, this would generally be due to the different volume of events for each instrument.

        To get the last Close price of the second instrument you could reference the last closed bar of the secondary series like the following:

        Code:
        Closes[1][0]



        You could also add a secondary Tick series to ensure the most recent Tick price is used in case there is not a closed bar for the current session on that instrument but there has been 1 tick. Ultimately if there is no data at all for the series, the script would need to wait until there is at least 1 bar or 1 tick depending on the secondary series you add before starting.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          If the time of the last bar in the secondary series PCLN was updated is 5 minutes ago, ie: 7:00 then

          SPY currently finishes 7:05 and OnBarUpdate fires.

          Will the secondary series Times[1][0] be 7:00 or 7:05?

          Comment


            #6
            Hello habibalex,

            In this example, you would get the 7:00 because that is the last "closed" bar in that series. The time you would retrieve this bar would be at 7:05 when you call Closes[1][0] but it would be the last Closed price from 7:00.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by mgco4you, Today, 09:46 PM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by wzgy0920, Today, 09:53 PM
            0 responses
            4 views
            0 likes
            Last Post wzgy0920  
            Started by Rapine Heihei, Today, 08:19 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Rapine Heihei, Today, 08:25 PM
            0 responses
            6 views
            0 likes
            Last Post Rapine Heihei  
            Started by f.saeidi, Today, 08:01 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Working...
            X