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 NullPointStrategies, Today, 05:17 AM
    0 responses
    43 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    65 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X