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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    93 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    138 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    123 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    73 views
    0 likes
    Last Post PaulMohn  
    Working...
    X