Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Advanced Order Handling - Partial exit

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

    Advanced Order Handling - Partial exit

    When using a structure similar to Reference Sample "Using OnOrderUpdate() and OnExecution() methods to submit protective orders" (https://ninjatrader.com/support/help...and_onexec.htm), how should a Strategy best partially close a position?

    For example:
    - During the evolution of a trade a stop loss order, "stopOrder", is updated to trail price activity.
    - Where the position must be partially closed in the lead up to Initial Margin prior to session close.
    - The "maxQuanty" is the maximum quantity within margin constraints, and "excessQuantity" is the quantity to be closed at market.

    Should the partial close be implemented as:
    1) "stopOrder" used to facilitate both
    a) the partial close at market and
    b) update quantity to monitor the evolving trade

    Code:
     stopOrder = ExitLong(EntryBarsArray, excessQuantity, signalName, fromEntrySignal);
     stopOrder = ExitLongStopMarket(EntryBarsArray, isLiveUntilCancelled, maxQuantity, stopPrice, signalName, fromEntrySignal);
    or 2)
    a) create a new Order, "onceOffOrder", to partially close
    b) update "stopOrder" to monitor the evolving trade

    Code:
     onceOffOrder = ExitLong(EntryBarsArray, excessQuantity, signalName, fromEntrySignal);
     stopOrder = ExitLongStopMarket(EntryBarsArray, isLiveUntilCancelled, maxQuantity, stopPrice, signalName, fromEntrySignal);
    Any insight is appreaciated.

    #2
    Hi Shansen, thanks for your question.

    The Signal Name property will be most useful when you want to partition orders. Give your entry orders different signal names and you can target them without guesswork. Since there are a number of ways to do the same thing in NinjaScript, I recommend testing any idea with the Sim101 account on a 10 second chart using some code like this:

    Code:
    //Note Entries Per Direction == 2 in this example
    
    bool submitOrder = false;
    
    OnBarUpdate()
    {
    
       if(State == State.Historical) return;
    
       if(!submitOrder)
        {
            //Set up a false entry condition just to test order submission in OnExecutionUpdate/OnOrderUpdate
            EnterLong("Entry0");
            EnterLong("Entry1");
            submitOrder = true;
        }   
    
    }
    That will make it easy to develop the logic for stop loss submission. Once it's nailed down move the logic to the main strategy script.

    Please let me know if I can assist any further.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    47 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    23 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    33 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    51 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X