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.

    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?

        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.

            Comment


              #7
              It works, thanks

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mindset, 04-21-2026, 06:46 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by M4ndoo, 04-20-2026, 05:21 PM
              0 responses
              144 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Started by M4ndoo, 04-19-2026, 05:54 PM
              0 responses
              71 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Started by cmoran13, 04-16-2026, 01:02 PM
              0 responses
              125 views
              0 likes
              Last Post cmoran13  
              Started by PaulMohn, 04-10-2026, 11:11 AM
              0 responses
              79 views
              0 likes
              Last Post PaulMohn  
              Working...
              X