Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMarketData vs OnBarUpdate

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

    OnMarketData vs OnBarUpdate

    Hello

    I am trying to code an indicator signalling when a bid - ask imbalance occurs and I'm not sure I understand which of the two codes below I should use in what situation

    Thank you

    Code:
    protected override void OnBarUpdate()
    {
        currentAsk = GetCurrentAsk();    
        currentAskVolume = GetCurrentAskVolume();
    .........
    }
    OR

    Code:
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {
        if (marketDataUpdate.MarketDataType == MarketDataType.Ask)
       {
             askVol = marketDataUpdate.Volume;    
             currentAsk = marketDataUpdate.Price;
       }
    }

    #2
    Hello itrader46,

    The GetCurrentAsk() / GetCurrentBid() would provide snap shots of the current ask or bid.



    OnMarketData would provide a continuous stream of the ask and bid instead of just a snap shot at the moment requested.


    Is this something where you are going to want to have this continuously update?
    If so, likely OnMarketData would be what you need.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I need to find three consecutive levels of ask - bid imbalances as soon as they occur. Would that mean I needed OnMarket Data?

      Comment


        #4
        Hello itrader46,

        Yes, I think you would want the stream of ask and bid from OnMarketData().
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Is there a way of separating the data on bars as well?

          I'm thinking of collecting the values I need from OnMarketData in some Lists, that I will be resetting then in OnBarUpdate on if(IfFirstTickOfBar). Would that work, or shall I use IfFirstTickOfBar directly in OnMarketData?
          Last edited by itrader46; 04-08-2020, 04:04 PM.

          Comment


            #6
            Hello itrader46,

            For bars you can add series of ask and bid which will update in OnBarUpdate().


            You can reset a list in OnBarUpdate() when IsFirstTickOfBar is true if you would like.
            IsFirstTickOfBar could also be used in OnMarketData().
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I am looking for some info regarding the MarketData events: are "marketDataUpdate.MarketDataType == MarketDataType.Last" and "marketDataUpdate.MarketDataType == MarketDataType.Ask"
              updated at the same time, if Last price == Ask Price? And so, does the code below make any sense?

              How exactly does the MarketDataType update happen?

              Code:
              protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
              {
                  if (marketDataUpdate.MarketDataType == MarketDataType.Ask)
                  {
                      currentAsk = marketDataUpdate.Price;
                  }
              
                  if (marketDataUpdate.MarketDataType == MarketDataType.Last)
                  {
                      lastPrice = marketDataUpdate.Price;
                      if (lastPrice == currentAsk)
                      {
                        askVol = marketDataUpdate.Volume;
                      }
                  }
              
              
              }
              Last edited by itrader46; 04-12-2020, 06:35 AM.

              Comment


                #8
                Helllo itrader46,

                The ask bid and last do not update at the same time. As the market update event occurs the marketDataUpdate.MarketDataType tells what kind of update the update is.

                The last will be at either the last ask or bid depending on which direction the execution was.

                Below is a link to an example.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                580 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                336 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
                554 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                552 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X