Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

exits based on strategy price vs actual fill price

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

    exits based on strategy price vs actual fill price

    Is there a way with the unmanaged approach to code and calculate the exits so that they're not based on the average filled price "Order.AverageFillPrice", but instead on the price the strategy would have wanted when the entry signal started?

    #2
    Hello giulyko00,

    You could save the current Close[0] (or GetCurrentAsk()/GetCurrentBid()) to a variable in OnBarUpdate() and use this as the base for the calculation when submitting the exits.

    private double marketPriceAtEntryCondition;

    In OnBarUpdate():

    if (/* condition to enter here */)
    {
    marketPriceAtEntryCondition = Close[0]; // you will want logic to ensure this condition only evaluates once until the trade is closed so this price is not continuously updated
    SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "longEntry");
    }

    In OnExecutionUpdate():
    if (exection.Name == "longEntry")
    {
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, 1, 0, Math.Min(GetCurrentBid() - TickSize, marketPriceAtEntryCondition - 10 * TickSize), "longEntry", "longExit");
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Ok thank you

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      163 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      82 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      125 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      206 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      184 views
      0 likes
      Last Post CarlTrading  
      Working...
      X