Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing bid/ask in OnExecutionUpdate

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

    Accessing bid/ask in OnExecutionUpdate

    I see that one can get historical bid/ask data within OnBarUpdate() with GetBid() for example and you can get realtime bid/ask data with OnMarketUpdate via MarketDataEventArgs. But what about OnExecutionUpdate()? That's where I create my stop loss orders but I want to make sure I don't try to enter a stop inside the bid/ask range which would result in an order rejection. I thought GetBid() for historical data or GetCurrentBid() for realtime data would work but those only work in OnBarUpdate(), So what can I do to get that information into OnExecutionUpdate()?

    #2
    Hello dweems,

    Thanks for your post.

    If you would like to get the current Bid or current Ask when an execution occurs, you could use GetCurrentBid() or GetCurrentAsk() within the OnExecutionUpdate() method.

    This could be seen by creating a test script that assigns GetCurrentBid()/GetCurrentAsk() to a double variable within the OnExecutionUpdate() method and printing out the double variable.

    For example, you could create a double variable called myBidPrice. assign GetCurrentBid() to myBidPrice, and print out myBidPrice. Then we could see the myBidPrice variable prints in a New > NinjaScript Output window. The myBidPrice will update and print out values each time an order execution occurs.

    See the attached sample script, UnmanagedTemplate, which demonstrates this.

    Let me know if I may assist further.
    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


      #3
      Thanks NinjaTrader_BrandonH for your reply. When I try to add GetCurrentBid() to my strategy within OnExecutionUpdate, the compiler says it can't be found. Also, I downloaded UnmanagedTemplate.cs that you provided but it doesn't include GetCurrentBid() anywhere within it. So I'm confused (nothing new....).

      Comment


        #4
        Hello dweems,

        Thanks for your note.

        I accidentally uploaded the wrong version of the example script. Please see the attached example script linked here.

        The example script uploaded in post #2 has also been changed to the proper file.

        You could see around line 124 that GetCurrentBid() could be used in the OnExecutionUpdate method of a strategy. If you run the strategy on a chart, you could see the value for GetCurrentBid() printing to the NinjaScript Output window when an execution occurs.

        Let me know if I may assist further.
        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
          Ah, that helps. I got GetCurrentBid() to build. But it still says I can't compile with GetBid() in OnExecutionUpdate(), which would get the historical data. Seems like that only works in OnBarUpdate(). Is there a work around to get that data into OnExecutionUpdate()?

          Comment


            #6
            Hello dweems,

            Thanks for your note.

            The GetBid() method can be used within OnExecutionUpdate() by calling the syntax Bars.GetBid(int index).

            For example, you could assign Bars.GetBid() to a variable named something like getBid within OnExecutionUpdate() and print out the getBid variable. The code might look something like this.

            Code:
            protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
            {
                double getBid = Bars.GetBid(CurrentBar);
                Print("getBid: " + getBid);
            }
            See this help guide page for more information and sample code: https://ninjatrader.com/support/help...nt8/getbid.htm

            Let me know if I may assist further.
            <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


              #7
              Duh! I should have seen that! My bad! Thanks for showing me what should have been obvious.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              52 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              130 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              70 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              43 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              47 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X