Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to determine beginning of a new bar and Price bid/ask status within OnMarketData

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

    How to determine beginning of a new bar and Price bid/ask status within OnMarketData

    I have an indicator that is Calculate.OnBarClose but utilizes OnMarketData for tick-by-tick logic. Since IsFirstTickOfBar cannot be used in OnMarketData, how is a new bar determined in this context? Also, in the eventargs (e) passed in OnMarketData when MarketDataType.Last, how is it determined what type of price the trade completed i.e. a bid or an ask? And how does the e.Price relate to the e.Bid and e.Ask properties of the eventargs object relative to the price type from the previous question? Any help is greatly appreciated!

    #2
    Originally posted by love2code2trade View Post
    Since IsFirstTickOfBar cannot be used in OnMarketData
    Says who?
    Did you try it?

    Comment


      #3
      Hello love2code2trade,

      You can save the CurrentBar value to a variable.

      If the CurrentBar is equal to the variable its the same bar. If CurrentBar is not equal to the variable, its a new bar. Resave the CurrentBar to the variable and trigger any actions you would like.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        thanks for your replies! ChelseaB, your solution works! Bltdavid i did try and it was not working. when i consulted the docs it warns against using IsFirstTickOfBar outside OnBarUpdate. ChelseaB can you shed some light as to why that is the case? Thanks!

        Comment


          #5
          I thought OnMarketData was invoked with a BarsInProgress context,
          which (I thought) meant that all Series were synced to the right data
          series input (because I thought there is an OnMarketData for every
          AddDataSeries as well as the primary chart series).

          Maybe no IsFirstTickOfBar because OnMarketData is called with
          ask/bid/last price changes, whereas OnBarUpdate is called on last
          price events only -- thus it probably doesn't make sense to check
          IsFirstTickOfBar on ask/bid price events.

          No prob, I stand corrected.

          Curious as to what ChelseaB has to say, too.



          Fyi, look at @Swing.cs to see Chelsea's suggested technique in
          action -- and yes, NT7's @Swing.cs used this same technique, so
          it's been around awhile.

          Comment


            #6
            Hello love2code2trade,

            IsFirstTickOfBar is directly related to the bar updating, which happens in OnBarUpdate(). Market data events can occur without the bar updating.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Check out the BuySellPressure indicator.
              eDanny
              NinjaTrader Ecosystem Vendor - Integrity Traders

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              599 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              344 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              558 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              557 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X