Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    JesseNinjaTrader Customer Service

    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.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ghoul, Today, 06:02 PM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        44 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        20 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        180 views
        0 likes
        Last Post jeronymite  
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Working...
        X