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

mulitple bracket trade management

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

    mulitple bracket trade management

    hi - I need to create a strategy that has the following orders

    1 entry order which is a stop order (Buy Stop / Sell Stop) of quantity 6
    3 targets each with quantity of 2 at different price levels
    A protective stop for the whole trade and for the whole quantity.

    I need these to behave like OCO's in the sense that if the stop gets hit, all the targets gets caneled.
    If the targets get hit, the stop decreases in quantity accordingly.
    I imagine this can be implemented with 1 stop or 3 separate stops (1 stop for each target)

    So the question is, can this be done in NT7 using the managed approach?

    #2
    Hello onnb1,

    Thank you for writing in. You can accomplish this using a single stop by adjusting the order quantity. Here is a very basic example:
    Code:
    #region Variables
    	IOrder stopLoss, targetOne, targetTwo, targetThree;
    	private int stopLossQuantity = 6;
    	private double stopLossPrice;
    #endregion
    protected override void Initialize()
    {
        CalculateOnBarClose = true;
    }
    protected override void OnBarUpdate()
    {
    	if(Rising(Close) && targetOne == null && targetTwo == null && targetThree == null) //Enter your conditions instead here
    	{
    		EnterLongStop(6, Close[0], "EnterLongStop");
    		//EnterLongStop(int quantity, double stopPrice, string signalName)
    
    		targetOne = ExitLongLimit(0, true, 2, Close[0] * 1.001, "ExitLongLimit1", "EnterLongStop"); //Profit Target Example
    		targetTwo = ExitLongLimit(0, true, 2, Close[0] * 1.0025, "ExitLongLimit2", "EnterLongStop"); //Profit Target Example
    		targetThree = ExitLongLimit(0, true, 2, Close[0] * 1.005, "ExitLongLimit3", "EnterLongStop"); //Profit Target Example
    		//ExitLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName, string fromEntrySignal)
    		stopLossPrice = Close[0] - (Close[0] * 0.001);
    		stopLoss = ExitLongStop(0, true, stopLossQuantity, stopLossPrice, "StopLoss", "EnterLongStop"); //Stop Loss Example
    	}
    }
    protected override void OnExecution(IExecution e)
    {
    	if((targetOne != null && targetOne == e.Order) || (targetTwo != null && targetTwo == e.Order) || (targetThree != null && targetThree == e.Order) && e.Order.Filled > 0)
    	{
    		stopLossQuantity -= e.Order.Filled;
    		stopLoss = ExitLongStop(0, true, stopLossQuantity, stopLossPrice, "StopLoss", "EnterLongStop");
    		if(stopLossQuantity == 0)
    			stopLossQuantity = 6;
    	}
    }
    Here is some more information on working with IOrders: http://ninjatrader.com/support/helpG...nt7/iorder.htm

    Here is more information on working with the OnExecution method: http://ninjatrader.com/support/helpG...nexecution.htm

    You could instead create the stop loss and profit targets as an ATM strategy first (see ATM Strategy methods: http://ninjatrader.com/support/helpG...gy_methods.htm) and then create a strategy to enter that calls the ATM strategy. This would work as well, but you would not be able to track strategy performance.

    Please let me know if you have any questions.
    Michael M.NinjaTrader Quality Assurance

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by AaronKoRn, Today, 09:49 PM
    0 responses
    6 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Today, 08:42 PM
    0 responses
    8 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    9 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,975 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    9 views
    0 likes
    Last Post rbeckmann05  
    Working...
    X