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

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.
    Brandon H.NinjaTrader Customer Service

    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 proptradingshop, Today, 11:29 PM
      0 responses
      2 views
      0 likes
      Last Post proptradingshop  
      Started by percy3687, Today, 11:04 PM
      0 responses
      1 view
      0 likes
      Last Post percy3687  
      Started by SantoshXX, Yesterday, 03:09 AM
      4 responses
      31 views
      0 likes
      Last Post SantoshXX  
      Started by f.saeidi, Today, 05:50 AM
      2 responses
      21 views
      0 likes
      Last Post f.saeidi  
      Started by futtrader, Today, 01:50 AM
      2 responses
      19 views
      0 likes
      Last Post futtrader  
      Working...
      X