Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting wrong GetCurrentBid and GetCurrentAsk data

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

    Getting wrong GetCurrentBid and GetCurrentAsk data

    Hi,

    it happens sometimes that when using GetCurrentBid or GetCurrentAsk I get wrong data. When comparing with IB data the problem is when setting a limit order it never gets filled because is out of the price requirements of the market.

    Is OnMarketData() the solution for this?

    On what part of the strategy this code
    protected override void OnMarketData(MarketDataEventArgs e)
    {
    }
    has to be set? I make this question because I need this data before OnBarUpdate() is executed.

    Thanks

    #2
    guillembm, yes OnMarketData() should help you here getting closer to the exact event timing of the Bid / Ask update events seen, the GetCurrentBid / GetCurrentAsk would be tied to the OnBarUpdate() timing.

    There would be no specific requirement where to call it in your script, you can ensure you process the call to the OnMarketData() updated variables early in your OnBarUpdate() then.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Continuing with this post I have another issue.

      I wrote this code before the onorderupdate:

      protected override void OnMarketData(MarketDataEventArgs e)
      {
      if (BarsInProgress == 1)
      {
      if (e.MarketDataType == MarketDataType.Ask)
      AskP = e.Price;

      if (e.MarketDataType == MarketDataType.Bid)
      BidP = e.Price;
      }
      }

      AskP and BidP are two varialbes I created

      I also wrote on onorderupdate:

      Print("AskPrice: " + AskP);
      Print("BidPrice: " + BidP);

      on the output window both values appear as 0.

      What I'm doing wrong?

      Comment


        #4
        guillembm, are you testing on live data or are you attempting this on historical data only?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          live data. Bars in progress = 1 is the same symbol than Bars in progress = 0 but with a different time frame

          Comment


            #6
            If it's the same instrument please try with BIP = 0 since BarsInProgress will return the first BarsInProgress series that matches the instrument for the event.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              It works, thanks

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by prdecast, Today, 06:07 AM
              1 response
              4 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by Christopher_R, Today, 12:29 AM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by chartchart, 05-19-2021, 04:14 PM
              3 responses
              577 views
              1 like
              Last Post NinjaTrader_Gaby  
              Started by bsbisme, Yesterday, 02:08 PM
              1 response
              15 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by i019945nj, 12-14-2023, 06:41 AM
              3 responses
              60 views
              0 likes
              Last Post i019945nj  
              Working...
              X