Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnExecutionUpdate Get Entry Price

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

    OnExecutionUpdate Get Entry Price

    Hello,

    I am trying to get the entry price of my positions to store as a double to use elsewhere in my code. This is what I have right now:

    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    breakevenprice = execution.Order.AverageFillPrice;
    }


    This code is doing as intended and giving me the average fill price. The issue is on candles where the execution is a profit target or a stop loss, or a profit target and an entry. See image:Click image for larger version

Name:	Screen Shot 2022-02-02 at 4.11.00 AM.png
Views:	331
Size:	99.8 KB
ID:	1187993

    With the code I am currently using, the double breakeven price will calculate as the profit target or stop loss when that is the execution type, and on candles with both entries and stop losses will trigger as either. How can I tell OnExecutionUpdate to change breakevenprice only when the execution type is long or short? And not profit targets, stop losses, or exits on session closes?

    Thanks​

    #2
    Hello thereyoflite1,

    Thank you for your post.

    Are you keeping track of your entry orders using a variable like illustrated in SampleOnOrderUpdate here:

    https://ninjatrader.com/support/help...and_onexec.htm

    If you are, you could check to see if the Order associated with the Execution is an entry order and update the double breakeven price accordingly so it would not change if the order is another order type like a stop or an exit on session close order.

    Please let us know if we may be of further assistance to you.

    Comment


      #3

      Thank you,

      I was able to resolve this by setting breakevenprice equal to averagefill when the entry is "mystring" in the OnOrderUpdate section.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      21 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      50 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Working...
      X