Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit Position at limit and Enter position in opposite direction at Limit

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

    Exit Position at limit and Enter position in opposite direction at Limit

    I would like to exit a position at limit and enter another position in the opposite direction at limit. Something like this

    Code:
    ExitLongLimit(Close[0]);
    EnterShortLimit(NoOfContracts, Close[0]);

    But, I read in the documentation that

    Methods that generate orders to enter a position will be ignored if:
    A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction

    I'm guessing this is exactly what my code does above, so the EnterShortLimit will be ignored?

    Is there any other way I can achieve creating an exit at limit and enter at limit? Or I just have to exit at market and create an entry at limit and there is no way around it?


    I'm aware of dangling orders in the case of exiting in limit orders. So, I do have a fail safe that will trigger at a price x ticks away to close any open positions at Market.
    Last edited by admiralpanda; 02-24-2024, 10:46 PM.

    #2
    Hello admiralpanda,

    Thanks for your post.

    You would need to wait for the Exit order method to fill before calling your Enter order method to enter in the opposite direction.

    A condition could be created that checks if you are in a flat market position (Position.MarketPosition == MarketPosition.Flat) before calling EnterShortLimit() in your script.

    Position.MarketPosition: https://ninjatrader.com/support/help...etposition.htm

    Or, you could consider tracking order objects in OnOrderUpdate()/OnExecutionUpdate() to check if the Exit order OrderState is OrderState.Filled and then call your Enter order method to place a limit order to enter a short position.

    OnOrderUpdate(): https://ninjatrader.com/support/help...rderupdate.htm
    OnExecutionUpdate(): https://ninjatrader.com/support/help...tionupdate.htm
    SampleOnOrderUpdate: https://ninjatrader.com/support/help...and_onexec.htm

    However, it seems that you are submitting the orders to the current close price (current market price).

    If you are trying to reverse a position from a long position to a short position, you could just call EnterShort() when you are in a long position to automatically reverse your position from long to short.

    From the Managed Approach help guide:

    "Entry() methods will reverse the position automatically. For example if you are in a 1 contract long position and now call EnterShort() -> you will see 2 executions, one to close the prior long position and the other to get you into the desired 1 contract short position."

    Managed Approach: https://ninjatrader.com/support/help...d_approach.htm
    Last edited by NinjaTrader_BrandonH; 02-25-2024, 05:10 PM.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      I've a condition parameter in the strategy that checks to enter and exit at limit. Otherwise it reverses using the EnterShort() or EnterLong() methods.

      Thanks for the code snippets, I'll look into those.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      566 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      547 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X