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

Closing Position on Fully Leveraged Rithmic account

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

    Closing Position on Fully Leveraged Rithmic account

    Hello,

    I'm having problems with one of my trading accounts. I'm having trouble getting out of a position. It throws up the error:

    "Rejected at RMS - Total sell quantity of account would exceed its limit"

    It is a new Funded Topstep account. The maximum number of contracts according to the scaling plan is 2.

    I use the Addons/Accounts API to create and submit orders using some ChartTrader custom UI code.


    The flow that causes the error is as follows:

    Submit Market order for 1 contract.
    When the market order is filled, Submit a Limit Order (target) and a Stop Market Order (stop-loss)
    Submit Market order for a second contract
    When the market order is filled, Submit a Limit Order (target) and a Stop Market Order (stop-loss)

    I am now at Max leverage on this account. With an open position of 2 contracts, Plus 2 Limit target orders and 2 StopLoss orders.

    I want to close the position at the market.

    So I'm doing the following:

    firstly. Cancel the stop-loss and target orders;

    account.Cancel(new [] { target1, stop1, target2, stop2 });

    Then submit a market order to flatten the account:

    account.CreateOrder(....)

    at this point it throws up the Error: "Rejected at RMS - Total sell quantity of account would exceed its limit"


    I believe the issue is the timing of the requests. When the Market Order to flatten the account is submitted, the stop/target orders haven't fully been cancelled. At least one order is still active, and therefore the market order to exit the position plus the not-yet-cancelled stop/target orders would take me over the position size limit.

    The issue only seems to happen on one account. A new TopStep Express Funded account. I'm able to reproduce it very consistently. But it doesn't happen on any other accounts. Even a Practice account that TopStep has set up with the same parameters.

    Is there anything incorrect with the flow I'm using to close this position?

    A "Thread.Sleep(100)" resolves things after the account.Cancel() request. But this is not an idea solution. I also can't use account.Flatten() as The code in question keeps track of its Brackets and knows that it is managing a position of 2... There might be other positions open under normal circumstances.

    #2
    Hello kevinenergy,

    Thanks for your post.

    You would need to wait for the cancel of the stop/target orders to complete before submitting your market order to exit the position.

    OnOrderUpdate() could be used to track order objects and detect if the stop/target orders OrderState == OrderState.Cancelled and then you could submit your market order to close the position.

    See the help guide documentation and reference sample below for more information.

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

    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DJ888, Today, 10:57 PM
    0 responses
    6 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    158 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Today, 09:29 PM
    0 responses
    7 views
    0 likes
    Last Post Belfortbucks  
    Started by zstheorist, Today, 07:52 PM
    0 responses
    7 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    151 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Working...
    X