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 NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              67 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              142 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              76 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              47 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              51 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X