Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Below bid / above ask T&S

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

    Below bid / above ask T&S

    I am trying to replicate the T&S window in a superdom column, but I am not getting the results I expect. In the screenshot you can see that the T&S shows above ask trades, but my superdom column doesn't show the same thing. Is that code different somehow?

    Code:
    protected override void OnMarketData(MarketDataEventArgs e)
    {
    if (e.MarketDataType == MarketDataType.Last)
    {
    if (e.Volume >= BlockAlertTradeSize)
    {
    if (e.Price == e.Ask)
        priceOutput.Add(new PriceOutput() { Output = string.Format("{2}\t{1}\t{0}", e.Time.ToLongTimeString(), (e.Price%100).ToString("#.00"), e.Volume), TextColor = TextColors.AtAsk, BlockAlert = true });
    else if (e.Price == e.Bid)
        priceOutput.Add(new PriceOutput() { Output = string.Format("{2}\t{1}\t{0}", e.Time.ToLongTimeString(), (e.Price%100).ToString("#.00"), e.Volume), TextColor = TextColors.AtBid, BlockAlert = true });
    else if (e.Price > e.Ask)
        priceOutput.Add(new PriceOutput() { Output = string.Format("{2}\t{1}\t{0}", e.Time.ToLongTimeString(), (e.Price%100).ToString("#.00"), e.Volume), TextColor = TextColors.AboveAsk, BlockAlert = true });
    else if (e.Price > e.Bid && e.Price < e.Ask)
        priceOutput.Add(new PriceOutput() { Output = string.Format("{2}\t{1}\t{0}", e.Time.ToLongTimeString(), (e.Price%100).ToString("#.00"), e.Volume), TextColor = TextColors.Between, BlockAlert = true });
    else if (e.Price < e.Bid)
        priceOutput.Add(new PriceOutput() { Output = string.Format("{2}\t{1}\t{0}", e.Time.ToLongTimeString(), (e.Price%100).ToString("#.00"), e.Volume), TextColor = TextColors.BelowBid, BlockAlert = true });
    }
    Attached Files

    #2
    Hello habibalex, thanks for writing in.

    The T&S windows is essentially an OnMarketData() method wrapped in a GUI, so the data you are seeing from T&S should match any OnMarketData method of the same instrument.

    As far as getting your custom column to match, this would require deeper dive into the custom column script by printing all of the values that OnMarketData is producing and comparing them against the T&S window to see where it diverges.

    Please let me know if I can assist any furher.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi habibalex,

      I was thinking about building (is still on my backlog list) the logic to identify when transactions occurred above the ask or below the ask and was going to first try the basic logic constructs seen in this inexact but slightly related post ....


      https://ninjatrader.com/support/foru...87#post1128387


      Code:
      protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
      {
      if (marketDataUpdate.MarketDataType == MarketDataType.Last)
      {
      prevPrice = currentPrice;
      currentPrice = marketDataUpdate.Price;
      }
      
      Print("prevPrice: " + prevPrice);
      Print("currentPrice: " + currentPrice);
      
      Print("");
      if (prevPrice > currentPrice)
      {
      Print("Previous price is greater than current price.");
      }
      else if (prevPrice < currentPrice)
      {
      Print("Previous price is less than current price");
      }
      else if (prevPrice == currentPrice)
      {
      Print("Previous price is equal to current price.");
      }
      }

      Comment


        #4
        In case anyone stumbled upon this, the e.Ask and e.Bid prices will always be at whatever trade price occurred last or (which is good to see what side the trade occurred on for delta). If you want to get the last level 1 bid or ask update, use the if(marketDataType == MarketDataType.Bid) or Ask. These updates occur after the trades have finished.

        The NT8 T&S uses this to get trades above / below the bid/ask for highlighting

        Comment


          #5
          Originally posted by habibalex View Post
          In case anyone stumbled upon this, the e.Ask and e.Bid prices will always be at whatever trade price occurred last or (which is good to see what side the trade occurred on for delta). If you want to get the last level 1 bid or ask update, use the if(marketDataType == MarketDataType.Bid) or Ask. These updates occur after the trades have finished.

          The NT8 T&S uses this to get trades above / below the bid/ask for highlighting
          I modified the code in this thread to attempt to distinguish between trades that "appear to have" taken place outside the best bid or offer and I'm seeing the "prices will always be at whatever trade price occurred last" issue.

          Anyone have any ideas how to do this? Or alternatively, can anyone point me in the right direction?


          Code:
          protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
                  {
                      //get prices
                      if (marketDataUpdate.MarketDataType == MarketDataType.Bid)
                      {//current bid
                          currentBid = marketDataUpdate.Bid;
                      }
                      else if (marketDataUpdate.MarketDataType == MarketDataType.Ask)
                      {//current ask
                          currentAsk = marketDataUpdate.Bid;
                      }
                      else if (marketDataUpdate.MarketDataType == MarketDataType.Last)
                      {//current price
                          currentPrice = marketDataUpdate.Last;
                      }
          
                      //compare them and print them
                      if (currentPrice > currentAsk)
                      {
                          Print("Aggressive buy at: " + currentPrice);
                      }
                      else if (currentPrice < currentBid)
                      {
                          Print("Aggressive sell at: " + currentPrice);
                      }
                  }​

          Comment


            #6
            Hello WalterSkinner,

            Thank you for your note.

            Are you seeing these results in real time or are you evaluating historical data? OnMarketData() is a real-time data stream, and although it can be called historically with Tick Replay the value will only be the last market data, and not the bid or ask market data. If needed for historical data, you can add an ask or bid series and compare those prices:


            There is a Time and Sales SuperDOM column available in the user app share that seems to have a feature that will show if a trade is at, above, or below the ask or bid. You could review the script posted in the app share with your own to see the similarities and differences.

            This indicator is publicly available on our NinjaTrader Ecosystem website:
            Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

            Note — To import NinjaScripts you will need the original .zip file.

            To Import:
            1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
            2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
            3. Select the downloaded .zip file
            4. NinjaTrader will then confirm if the import has been successful.

            Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

            Once installed, you may add the indicator to a chart by:
            • Right-click your chart > Indicators... > Select the Indicator from the 'Available' list on the left > Add > OK

            Here is a short video demonstration of the import process:
            Please let me know if I can be of further assistance.

            The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
            Emily C.NinjaTrader Customer Service

            Comment


              #7
              Thank you so much for that, it looks like it should answer all of my questions and then some.

              Comment


                #8
                Nice indicator but why does it only work in real time and not on Playback - I have never been able to get T&S data to follow what happens in the T&S box ie Prints Below the Bid but my code says at Bid, same for Above Ask. Yet the NT T&S clearly show the trade at being above or below respectively.
                It's very confusing as to what to do / how to get prints to match the T&S window.
                Last edited by Mindset; 05-07-2023, 04:04 AM.

                Comment


                  #9
                  Originally posted by Mindset View Post
                  Nice indicator but why does it only work in real time and not on Playback - I have never been able to get T&S data to follow what happens in the T&S box ie Prints Below the Bid but my code says at Bid, same for Above Ask. Yet the NT T&S clearly show the trade at being above or below respectively.
                  It's very confusing as to what to do / how to get prints to match the T&S window.
                  This would seem to suggest that the bid/ask/last are getting jumbled out of sequence, possibly because of the same timestamp so the sequencing information is no longer correct. Are you replaying data you recorded from realtime or that you downloaded from NinjaTrader in this case? And are you saying it's out of the NBBO inside bid/offer based on how the UI looks on the superdom or based on code that's outputting some sort of diagnostic? I ask this because the UI is only updated once per second during replay.
                  Bruce DeVault
                  QuantKey Trading Vendor Services
                  NinjaTrader Ecosystem Vendor - QuantKey

                  Comment


                    #10
                    Hi Bruce
                    I can accept it doesn't necessarily get it right in replay - though with tick data it really ought to - but I have tested in real market conditions in real time and it doesn't pick it up.
                    I am working on what Habibablex wrote about testing for the updated price type?
                    I mean it seems simple enough in code to ask what is the current lets say ask and if the trade is above that fire off an event. V v for the bid.

                    Comment


                      #11
                      Save off the inside Bid / inside ask by testing for if e.MarketDataType == MarketDataType.Bid / Ask and save those off as variables (insideBid / insideAsk).

                      Then in (e.MarketDataType == MarketDataType.Last) if it's e.Price <= e.Bid && < insideBid it'll be "outside". Use e.Price >= e.Ask && insideAsk for the other side.

                      That should work in replay also.

                      Comment


                        #12
                        Hi
                        thanks for this. I can save the insideBid/Ask but
                        not getting the above ask / below bid condition right.

                        My code( just using the above ask condition) is
                        ​protected override void OnMarketData(MarketDataEventArgs e)
                        {

                        if ( e.MarketDataType == MarketDataType.Bid)
                        insideBid = (double)e.Bid;
                        if ( e.MarketDataType == MarketDataType.Ask)
                        insideAsk = (double)e.Ask;
                        double currentPrice = (double)e.Last;

                        if(e.MarketDataType == MarketDataType.Last)
                        {

                        if(e.Price> insideAsk)
                        Draw.TextFixed(this,"ggg",DateTime.Now.ToString("H H:mm:ss")+"Above Ask",TextPosition.Center);
                        }

                        }​

                        Comment


                          #13
                          in your if statements, set :
                          insideBid = e.Price
                          insideAsk = e.Price
                          currentPrice = e.Price
                          change the 2nd / 3rd if to else if for both not just if

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by ageeholdings, Today, 07:43 AM
                          0 responses
                          7 views
                          0 likes
                          Last Post ageeholdings  
                          Started by pibrew, Today, 06:37 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post pibrew
                          by pibrew
                           
                          Started by rbeckmann05, Yesterday, 06:48 PM
                          1 response
                          14 views
                          0 likes
                          Last Post bltdavid  
                          Started by llanqui, Today, 03:53 AM
                          0 responses
                          6 views
                          0 likes
                          Last Post llanqui
                          by llanqui
                           
                          Started by burtoninlondon, Today, 12:38 AM
                          0 responses
                          12 views
                          0 likes
                          Last Post burtoninlondon  
                          Working...
                          X