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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        89 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        135 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        68 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        119 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        69 views
        0 likes
        Last Post PaulMohn  
        Working...
        X