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 on session close

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

    Exit on session close

    I am running into an issue using TDA. I currently have logic that enters a trade then OnExecutionUpdate it sets a stop loss/profit order. The strategy is marked to exit on session close so my assumption is that if those orders are open it will close those and exit on session close. This does not seem to be the case here as it does not cancel those orders and instead I get the following error when the session closing orders are submitted.

    REJECTED: This order may result in an oversold/overbought position in your account. Please check your position quantity and/or open orders

    What is the best way to work around this? My strategy is running on 1 min bars. I would like to avoid having to have my code cancel open orders at a specific time as that is a bit hacky and leaves me susceptible to a large move at the end of the day. Why wouldn't the Exit on session close, close/cancel any other open orders generated by the strategy first?

    #2
    Hello proptradingshop,

    Thank you for your post.

    TD Ameritrade does not allow a market order to close a position unless stop and target orders have been canceled first; what I suspect is happening here is that you have working stop and/or target orders at the time ExitOnSessionClose is triggered. When that action triggers, cancellation requests are sent at the same time as the market order to close any open positions. With TDA, if the cancellations have not been received/acknowledged yet by the time the close position order is sent, the order can be rejected with the error you mentioned. Typically, when closing positions with TDA, you must explicitly cancel stops/targets first and then once the cancellation is confirmed, you may then submit an order to close the position. If you use Set() methods to submit stops and targets, you could use Account.Cancel prior to closing a position as demonstrated in the example here:
    Hi, I have multiple open positions and at the end of the day if they don't hit their respective Target/Stop, I would like cancel the linked OCO's and close the positions. I know TD Ameritrade makes things difficult, what would be the best way to do this? I've tried various ways but cant seem to get it to work. Any help would be


    To work around this, you may not be able to use ExitOnSessionClose with TD Ameritrade. You could use time filters in your strategy and at a specific time (although you said this seems a bit hacky, several developers use start/end time filters in their logic) and once the end time is hit, you would need to first cancel out orders and then submit a market order, such as ExitLong() or ExitShort(), to exit the position. We have an example of using time filters to limit trading hours in the help guide here:


    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by fx.practic, 10-15-2013, 12:53 AM
    5 responses
    5,406 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by Shai Samuel, 07-02-2022, 02:46 PM
    4 responses
    98 views
    0 likes
    Last Post Bidder
    by Bidder
     
    Started by DJ888, Yesterday, 10:57 PM
    0 responses
    8 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    160 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Yesterday, 09:29 PM
    0 responses
    9 views
    0 likes
    Last Post Belfortbucks  
    Working...
    X