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 CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        56 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        34 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        195 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        359 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        281 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X