Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitLong - OnBarClose

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

    ExitLong - OnBarClose

    I have a strategy using ExitLong for the exit.

    The exit orders are not placed (do not appear on the chart) until the next bar closes after the entry.

    If I use SetProfit the exit order appears as soon as the position is entered (on the same bar).

    Is there a way to have ExitLong engage at the same time the opening order is placed?

    I am finding that the price can move beyond where the stop is set before the ExitLong order is generated.

    #2
    Hello sdauteuil,

    The Set methods will be submitted on the fill of the entry so that would be more immediate. If you wanted to have the exit placed at the same time as the entry you would need to submit that based on the entry fill. I presume you mean a type of order which you can keep open like a limit or stop limit, if you submit an ExitLong() after the entry fill you will see that it just closes the position immediately.

    To submit any order based on the fill of another order you could use OnExecutionUpdate. https://ninjatrader.com/support/help...lightsub=onexe

    I look forward to being of further assistance.

    Comment


      #3
      I have a bool variable which keeps keeps the ExitLong() working

      Where is OnExecutionUpdate placed in the code? Is it placed under BarsInProgress == 0 (primary series)

      Do you have any sample code?


      Currently

      If BarsInProgress != 0
      return

      // entry code logic
      {
      EnterLong()
      bool variable PositionOpen = true
      }

      //exit code
      if (Position.MarketPosition == MarketPosition.Long && PositionOpen == true)
      {
      ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - StopLoss * TickSize, "Stop Loss", "");
      ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + ProfitTarget * TickSize, "Profit Target", "");
      PositionOpen = false;
      }

      Comment


        #4
        Hello sdauteuil,

        There is a sample that shows the OnExecutionUpdate override syntax in the link in the last post. You would put the override in your script similar to how OnBarUpdate is.

        You can also find a sample that uses this override here: https://ninjatrader.com/support/help...and_onexec.htm


        I look forward to being of further assistance.

        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
        41 views
        0 likes
        Last Post CarlTrading  
        Working...
        X