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

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 DJ888, 04-16-2024, 06:09 PM
                4 responses
                12 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by terofs, Today, 04:18 PM
                0 responses
                7 views
                0 likes
                Last Post terofs
                by terofs
                 
                Started by nandhumca, Today, 03:41 PM
                0 responses
                6 views
                0 likes
                Last Post nandhumca  
                Started by The_Sec, Today, 03:37 PM
                0 responses
                3 views
                0 likes
                Last Post The_Sec
                by The_Sec
                 
                Started by GwFutures1988, Today, 02:48 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Working...
                X