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

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.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by arvidvanstaey, Today, 02:19 PM
    4 responses
    11 views
    0 likes
    Last Post arvidvanstaey  
    Started by samish18, 04-17-2024, 08:57 AM
    16 responses
    60 views
    0 likes
    Last Post samish18  
    Started by jordanq2, Today, 03:10 PM
    2 responses
    9 views
    0 likes
    Last Post jordanq2  
    Started by traderqz, Today, 12:06 AM
    10 responses
    18 views
    0 likes
    Last Post traderqz  
    Started by algospoke, 04-17-2024, 06:40 PM
    5 responses
    47 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X