Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MarketDataUpdate Trades Printing Twice

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

    MarketDataUpdate Trades Printing Twice

    I'm trying to get the current ask, bid, and trades at each bid / ask. For some reason the code below duplicates the trades (14 contracts trade displays twice). See below:

    CODE:
    PHP Code:
    protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
    {
    
         if (marketDataUpdate.MarketDataType == MarketDataType.Last){
    
              if (marketDataUpdate.Price >= marketDataUpdate.Ask)
              {
                   double currentAsk = GetCurrentAsk();
                   Print("The Current Ask price is: " + currentAsk);
    
                   double currentBid = GetCurrentBid();
                   Print("The Current Bid price is: " + currentBid);
                   Print(marketDataUpdate.Volume + " contracts traded at asking price " + marketDataUpdate.Ask + " at time " + marketDataUpdate.Time);
               }
    
               else if (marketDataUpdate.Price <= marketDataUpdate.Bid)
               {
                    double currentAsk = GetCurrentAsk();
                    Print("The Current Ask price is: " + currentAsk);
    
                    double currentBid = GetCurrentBid();
                    Print("The Current Bid price is: " + currentBid);
                    Print(marketDataUpdate.Volume + " Contracts Traded at bidding price " + marketDataUpdate.Bid + " at time " + marketDataUpdate.Time);
                }
         }
    } 
    


    OUTPUT:
    The Current Ask price is: 2984.75
    The Current Bid price is: 2984.5
    14 Contracts Traded at bidding price 2984.5 at time 8/1/2019 12:01:02 AM
    The Current Ask price is: 2984.75
    The Current Bid price is: 2984.5
    14 Contracts Traded at bidding price 2984.5 at time 8/1/2019 12:01:02 AM

    Any ideas would be much appreciated?
    Last edited by bc24fl; 08-09-2019, 06:51 PM.

    #2
    Hello bc24fl,

    The only item I can say which may affect this would be a secondary series, are you adding any secondary series in the script?

    You can test if that is the case with a print like the following:

    Print(BarsInProgress + " " + marketDataUpdate.ToString());

    If so, you can filter the events by Instrument or BarsInProgress properties.

    I look forward to being of further assistance.

    Comment


      #3
      I have this:

      HTML Code:
      else if (State == State.Configure)
                  {
                      // A 1 tick data series must be added to the OnStateChange() if using a Tick Resolution (our second example call below in OnBarUpdate())
                      // used by orderflow functions so cannot remove
                      AddDataSeries(BarsPeriodType.Tick, 1);
                  }

      Comment


        #4
        Hello bc24fl,

        Yes in that case we would see multiple updates to OnMarketData, you can use my prior comment as the way to filter the override. The BarsInProgress can be used conditionally to print only one of the OnMarketData events instead of both.

        Code:
        if(BarsInProgress == 0)
        {
        
        }
        I look forward to being of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        87 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        151 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        80 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        53 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        62 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X