Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

error in T&S or my code?

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

    error in T&S or my code?

    I wrote a simple code to display Time & Sales, but when I run it next to the NT Time & Sales, some of the buys show up as sells, and sells as buys according to the NT Time & Sales. Here is the code below that I used, is my code wrong, or is this an issue with the T&S?

    protectedoverridevoid OnMarketData(MarketDataEventArgs e)
    {



    if (e.MarketDataType == MarketDataType.Last && e.Price >= GetCurrentAsk())
    {


    Print(e.Price + " " + e.Volume);
    }



    if (e.MarketDataType == MarketDataType.Last && e.Price <= GetCurrentBid())
    {
    Print(" " + e.Price + " " + e.Volume);
    }



    }

    #2
    Hello,

    When you say that some of the buys show as sells, do you mean in every case? Are they just reversed?

    How are you determining that the buys are showing up as sells?
    MatthewNinjaTrader Product Management

    Comment


      #3
      reply

      No, only in some cases, the majority of prints match. Also some of the prints that occur in the NT Time & Sales window are omitted in the Output window where the results of my code displays.

      Originally posted by safetrading View Post
      I wrote a simple code to display Time & Sales, but when I run it next to the NT Time & Sales, some of the buys show up as sells, and sells as buys according to the NT Time & Sales. Here is the code below that I used, is my code wrong, or is this an issue with the T&S?

      protectedoverridevoid OnMarketData(MarketDataEventArgs e)
      {



      if (e.MarketDataType == MarketDataType.Last && e.Price >= GetCurrentAsk())
      {


      Print(e.Price + " " + e.Volume);
      }



      if (e.MarketDataType == MarketDataType.Last && e.Price <= GetCurrentBid())
      {
      Print(" " + e.Price + " " + e.Volume);
      }



      }

      Comment


        #4
        Hello,

        Can you please change your code to not use:

        GetCurrentAsk()

        This method is typically used in OnBarUpdate(). I would recommend just storeing the ask price in a variable since you already have OnMarketData override in your code.

        Code:
        if (e.MarketDataType == MarketDataType.Ask)
        {
               CurrentAskPrice = e.Price;
        }
        
        then:
        
        if (e.MarketDataType == MarketDataType.Last && e.Price >= CurrentAskPrice)
                          {     
        
        
                          Print(e.Price + "    " + e.Volume);
                          }
        I would not expect any issues with the above code, all prints will be displayed.
        Last edited by NinjaTrader_Brett; 05-18-2012, 02:35 PM.
        BrettNinjaTrader Product Management

        Comment


          #5
          reply

          Thanks, that did it. Have a great weekend.

          Originally posted by NinjaTrader_Brett View Post
          Hello,

          Can you please change your code to not use:

          GetCurrentAsk()

          This method is typically used in OnBarUpdate(). I would recommend just storeing the ask price in a variable since you already have OnMarketData override in your code.

          Code:
          if (e.MarketDataType == MarketDataType.Ask)
          {
                 CurrentAskPrice = e.Price;
          }
           
          then:
           
          if (e.MarketDataType == MarketDataType.Last && e.Price >= CurrentAskPrice)
                            {     
           
           
                            Print(e.Price + "    " + e.Volume);
                            }
          I would not expect any issues with the above code, all prints will be displayed.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          637 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          366 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          107 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          569 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          571 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X