• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Modifying a filled StopLimit Order, is it possible?

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

    Modifying a filled StopLimit Order, is it possible?

    Hi There,

    I am working on a backtest strategy on sugar no.11 using the backtesting tool and I am entering a long order using the unmanaged approach and can't seem to adjust the stoplimit value after the order has been filled.

    Is this normal?

    I have a reference the previous order (its set as a private member variable in the strategy and then I call

    private IOrder oldO;

    ... in my main method()....
    if(tightenStop ){

    ChangeOrder(oldO, oldO.limitPrice, oldO.quantity, newStopLimitVal);

    }


    When I look at the order directly afterwards the stopLimit is unchanged. I have set the unmanaged = true as well in my initialize block and have followed all the examples. I have 12 years programming experience so I can't see anything wrong with the code or API calls its just seems something configuration wise isn't right.

    Thanks in advance...

    Code:
                    private IOrder prevLongTrade = null;
    		private IOrder prevShortTrade = null;
    		
    		private double originalOrderAtr = 0;
    		
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
    			Unmanaged = true;
    			AccountSize = 100000;
    			EntriesPerDirection = 6;
    			ClearOutputWindow();
    
    .....................
    
                            CalculateOnBarClose = true;
            }
    
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    			/*
    			 * Long Part
    			 */
    			
    			//place the order
    			if(prevLongTrade == null)
    			{
    				//create a new one
    				Print("Creating new order...");
    				prevLongTrade = SubmitOrder(0, OrderAction.Buy, OrderType.StopLimit, orderAmt, earlyLongPrice, earlyLongStop, "", "longMid" );
    				
    				Print(String.Format("NewLongTrade: {0} LimitPrice: {1} StopPrice: {2} Filled: {3}", prevLongTrade.OrderState, prevLongTrade.LimitPrice, prevLongTrade.StopPrice, prevLongTrade.Filled));
    				
    
    			}else{
    				//use the old one and modify it...
    				Print(String.Format("PrevLongTrade: {0} LimitPrice: {1} StopPrice: {2} Filled: {3}", prevLongTrade.OrderState, prevLongTrade.LimitPrice, prevLongTrade.StopPrice, prevLongTrade.Filled));
    				
    if(prevLongTrade.OrderState == OrderState.Working){
    					Print("modifying/cancelling open working order...");
    					Print(String.Format("adjusting price orig[{0}] new[{1}] & Stop loss orig[{2}] new[{3}] ", prevLongTrade.LimitPrice, earlyLongPrice, prevLongTrade.StopPrice, earlyLongStop));
    					ChangeOrder(prevLongTrade, prevLongTrade.Quantity, earlyLongPrice, earlyLongStop);
    					Print(String.Format("NewLongTrade: {0} LimitPrice: {1} StopPrice: {2} Filled: {3}", prevLongTrade.OrderState, prevLongTrade.LimitPrice, prevLongTrade.StopPrice, prevLongTrade.Filled));
    
    }else if(prevLongTrade.OrderState == OrderState.Filled){
    
    Print("adjusting Stop loss...");
    					
    if(diffGreaterThanX){
    ....
    if(newStop > prevLongTrade.StopPrice){
    	ChangeOrder(prevLongTrade, prevLongTrade.Quantity, prevLongTrade.LimitPrice, 0);
    	Print(String.Format("NewTightenedLongTrade: {0} LimitPrice: {1} StopPrice: {2} Filled: {3} : qty: {4}", prevLongTrade.OrderState, prevLongTrade.LimitPrice, prevLongTrade.StopPrice, prevLongTrade.Filled, prevLongTrade.Quantity));					}										
    			}
    		}
    	}
    }
    Hope that looks ok in the code window

    #2
    Hello maikeru,

    Thank you for your post.

    You cannot change an order that has been filled.
    When using SubmitOrder() you are only submitting one order (in this case the entry order), if you want to use a StopLoss or ProfitTarget you will need to submit these separately when using the Unmanaged Approach and adjust them separately as well.

    For information on the Unmanaged Approach please visit the following link: http://www.ninjatrader.com/support/h...d_approach.htm

    Please let me know if I may be of further assistance.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Patrick

      Thanks for that patrick, it wasnt clear in the docs what is possible when the order is in each of its states.

      Would you be able to draw out a simple example then of a limit order and a stop loss I would want to tighten.

      And going on from that, if I had a number of orders in one direction as I was scaling in then is it possible for the orders to have different stop limits applied to them or would I only have one stop per direction?

      (e.g. four long trades and one stop order managing them all?)

      And finally this can only be done via the unmanaged order system, or is there a way to do it via managed style orders as I can't seem to see any open orders when I use the Performance object within my strategy even if I have a filled order it wont show up, do they only appear once they are closed?

      Thanks

      M

      Comment


        #4
        Hello M,

        Thank you for your response.

        We have a reference sample available at the following link concerning the modification of Stop Loss and Profit Targets using the Managed Approach: http://www.ninjatrader.com/support/f...ead.php?t=3222

        It is possible for different orders to have different Stop Losses applied. If using the Unmanaged Approach you would use IOrder object of the order you wish to amend, and if using the Managed Approach you would use the string fromEntrySignal to adjust a Stop Loss for an entry order.

        For information on the Managed Approach please visit the following link: http://www.ninjatrader.com/support/h...d_approach.htm

        For information on the Unmanaged Approach please visit the following link: http://www.ninjatrader.com/support/h...d_approach.htm

        The Performance object will pull information based on trades generated by the strategy, so the trade must be closed before that information is pulled. For information of Performance please visit the following link: http://www.ninjatrader.com/support/h...erformance.htm

        Please let me know if I may be of further assistance.
        Last edited by NinjaTrader_PatrickH; 10-08-2012, 07:47 AM.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Thanks Patrick,

          I had a look at the examples and they actually use managed orders and basically amend onBarUpdate calls, useful but not really what I was talking about. I had tried this method initially but I was unable to amend the stoplimit on the filled managed order.

          Essentially I want to add a calculated stop limit to each order separately not on a per strategy basis by using a global sell/stop order.

          If I enter two limitorders at the same time looking for one to be filled one long, one short and they have stop limits added to them, once they are filled there is no way I can modify the stop limit on the order?

          By my understanding you would need to have a new SubmitOrder call of OrderType.Stop as once filled you cannot change the stopLimit price on this order via your api? I know some brokers allow you to do this via MT4 and saves another order floating around which may cost extra? Is there a reason this isn't possible?

          you say above:

          t is possible for different orders to have different Stop Losses applied. If using the Unmanaged Approach you would use IOrder object of the order you wish to amend....
          I'm a bit confused on this one sorry Patrick, I'm new to this API, when can you modify and unmanaged orders stoplimit and when can you not?

          thanks for all your help, I'm getting there slowly but surely.

          M

          Comment


            #6
            Hello M,

            Thank you for your response.
            If I enter two limitorders at the same time looking for one to be filled one long, one short and they have stop limits added to them, once they are filled there is no way I can modify the stop limit on the order?
            In this case you need to submit the Stop Limit orders separately from the two entry orders.
            Code:
            // Long Entry Order.
            longTrade = SubmitOrder(0, OrderAction.Buy, OrderType.StopLimit, 1, longLimitPrice, longStopPrice, "", "Enter Long");
            // Short Entry Order.
            shortTrade = SubmitOrder(0, OrderAction.Buy, OrderType.StopLimit, 1, shortLimitPrice, shortStopPrice, "", "Enter Short");
            
            // Stop Limit for Long Entry.
            longStop = SubmitOrder(0, OrderAction.Sell, OrderType.StopLimit, 1, longStopLimitPrice, longStopStopPrice, "", "Long Stop Loss");
            // Stop Limit for Short Entry.
            shortStop = SubmitOrder(0, OrderAction.BuyToCover, OrderType.StopLimit, 1, shortStopLimitPrice, shortStopStopPrice, "", "Short Stop Loss");
            Once the entry order is filled you can then use ChangeOrder() to modify the Stop Losses.
            By my understanding you would need to have a new SubmitOrder call of OrderType.Stop as once filled you cannot change the stopLimit price on this order via your api? I know some brokers allow you to do this via MT4 and saves another order floating around which may cost extra? Is there a reason this isn't possible?
            The function of NinjaScript is different from most trading platforms that allow the automated strategy development. However, you must understand the Unmanaged Approach if you plan to use this approach for submitting orders. Please visit the following link for more information: http://www.ninjatrader.com/support/h...d_approach.htm

            Please let me know if you have additional questions on this matter.
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              Thanks Patrick!

              I'll try this method out and see how I get on, thanks again for your time and help!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by benjamind10, Today, 07:27 PM
              0 responses
              2 views
              0 likes
              Last Post benjamind10  
              Started by YevhenShynkarenko, Today, 06:07 PM
              0 responses
              4 views
              0 likes
              Last Post YevhenShynkarenko  
              Started by StevenNelson, Today, 04:07 PM
              3 responses
              10 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by Matthew Spositi, Today, 03:28 PM
              2 responses
              8 views
              0 likes
              Last Post Matthew Spositi  
              Started by faisamtrader, Today, 01:30 PM
              2 responses
              20 views
              0 likes
              Last Post NinjaTrader_ChrisL  
              Working...
              X