Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BidAsk from Times&Sales

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

    BidAsk from Times&Sales

    Hello,

    how can one access the bidask that is shown in Times&Sales to use in a code eg to print. As everything can be done in NinjaTrader I assume this will also be possible. I dont mean to get bidask from level2 data because I dont have level2 datafeed. I only need the bid and ask from the top of Times&Sales to plot the 2 numbers with an indicator.

    Thank you!
    Tony

    #2
    Hello tonynt,

    Thank you for your post.

    You could access the Bid/Ask values from level 1 data by using the OnMarketData method. OnMarketData includes but is not limited to level 1 data for the bid, ask, last price and volume.

    The following example demonstrates how OnMarketData may be used to print level 1 Ask data to the NinjaScript Output window.
    protected override void OnMarketData(MarketDataEve ntArgs marketDataUpdate)
    {
    if (marketDataUpdate.MarketDataType == MarketDataType.Ask)
    Print(string.Format("Ask = {0} {1} ", marketDataUpdate.Price, marketDataUpdate.Volume ));
    }

    Here is a help guide link with more information about the OnMarketData method - https://ninjatrader.com/support/help...marketdata.htm

    Please let us know if we may further assist.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hello,

      thank you for your reply. I tried to print the bid and ask above the high of the last bar but I couldn´t make it working. Can you please give me a snippet?

      For the moment I have it with draw.textfixed on upper right corner. Would it be possible to plot it on right side in the mid (not on top and not on bottom). And why might there be a difference in the numbers from Times&Sales and the numbers from the code you gave me? (screenshot)
      Could it be that the reason is the time delay because in TS there are already new numbers and faster updating then the drawtext:

      if (marketDataUpdate.MarketDataType == MarketDataType.Bid)
      TBid=marketDataUpdate.Volume;
      if (marketDataUpdate.MarketDataType == MarketDataType.Ask)
      TAsk=marketDataUpdate.Volume;

      string str8 = string.Empty;
      str8+="Ask: " + TAsk;
      str8+="\r\nBid: " + TBid;
      Draw.TextFixed(this,"str8",str8, TextPosition.TopRight);

      And when testing it I see now that it does not change the numbers in the chart for few seconds, then it updates and for a short moment the numbes do match with TS.

      ??

      Thank you!
      Tony
      Attached Files
      Last edited by tonynt; 09-17-2020, 01:20 PM. Reason: add info

      Comment


        #4
        Hello tonynt,

        Thank you for your note.

        You could draw the Bid and Ask values in the middle of the right side of the chart by using a combination of OnMarketData and SharpDX to draw the Bid/Ask values on a chart.

        In the attached example script, we use OnMarketData to get the Bid and Ask values followed by assigning those values to a variable. We then use SharpDX within OnRender() to draw the Bid and Ask values saved in our variable.

        Additionally, here are a few help guide links for more information. The SampleCustomRender script that comes with NinjaTrader may be used alongside the 'Using SharpDX' help guide for learning SharpDX.

        Using SharpDX for Custom Chart Rendering - https://ninjatrader.com/support/help..._rendering.htm

        CharPanel - https://ninjatrader.com/support/help...chartpanel.htm

        OnMarketData - https://ninjatrader.com/support/help...marketdata.htm

        Please let us know if we may further assist.
        Attached Files
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Hello,

          thank you for your reply and that code. What I do not understand from this sample is how I can work with the bid volume and ask volume instead of bidprice and askprice eg if(bidvolume>askvolume) then do....

          And for the purpose of this topic: can I update a double or int in a script with the current bid and ask to use it eg for entry conditions or is only the printing in output window updating immediately with the values to see on the top of T&S?

          Does the following code make sense:

          protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
          {

          if (marketDataUpdate.MarketDataType == MarketDataType.Bid)
          {
          bidValue = string.Format("Bid: {0}", marketDataUpdate.Volume);
          bidVolume = marketDataUpdate.Volume;
          }

          if (marketDataUpdate.MarketDataType == MarketDataType.Ask)
          {
          askValue = string.Format("Ask: {0}", marketDataUpdate.Volume);
          askVolume = marketDataUpdate.Volume;
          }

          if(bidVolume>askVolume)
          {
          Print(string.Format("{0:HH:mm:ss} | Bid: {1}", marketDataUpdate.Time, bidVolume));
          // EnterLong("longEntry");
          }
          else if(bidVolume<askVolume)
          {Print(string.Format("{0:HH:mm:ss} | Ask: {1}", marketDataUpdate.Time, askVolume));
          // EnterShort("shortEntry");
          }

          Thank you!
          Tony
          Last edited by tonynt; 09-18-2020, 07:24 AM. Reason: add a code/solution(?)

          Comment


            #6
            Hello tonynt,

            Thank you for that information.

            The code you posted above could be used to get the volume of the last Bid tick and volume of the last Ask tick and save those values to variables for order entry comparison.

            If you would like to accumulate the volume for the Bid and Ask, you could use the += operator when assigning the volume to your variable, followed by resetting the variables within OnBarUpdate().

            You could add prints after your variables to confirm their output in a NinjaScript Output window.

            Please see the attached example strategy demonstrating how this could be accomplished.

            When looking at prints compared to the T&S window, please note that the Chart and the T&S windows both have a refresh rate of 250ms, however, since they are separate windows the volume values may not be in sync.

            Let us know if we may further assist.
            Attached Files
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            672 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X