Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Managed order with opposing limits

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

    Managed order with opposing limits

    Hello. I trust this has been raised many times but I am unable to find the correct keywords to search in the forum to solve my problem.

    I created a quick test scenario below to test limits & IOrders in a strategy:
    Code:
    protected override void OnBarUpdate()
    {
       if(Historical) return;
       if (started == false){
       started = true;
       entry = Close[0] - (4*TickSize);
       pt = Close[0] + (12*TickSize);
       long1 = EnterLongLimit(0,true,1,entry,"long1");   
       }
    }
    protected override void OnOrderUpdate(IOrder order)
    {
       if(long1 != null && long1 == order)
       {
          if(order.OrderState == OrderState.Filled)
          {
             short1 = EnterShortLimit(0,true,1,pt,"short1"); 
          }
       }
    }
    Once the buy limit is filled, the short sell limit gets cancelled which I assume is due to Internal handling for managed orders. Another sell limit order is generated, however, with the name "Close Position" and working with the price I specified on the sell limit that was cancelled. Why is this happening? I assumed I needed to use unmanaged orders to do what I was trying to do but it seems that, in an unconventionally way, this has prevented me from going down that track.

    22/05/2013 7:15:06 p.m. Entered internal PlaceOrder() method at 22/05/2013 7:15:06 p.m.: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=1666.25 StopPrice=0 SignalName='long1' FromEntrySignal=''

    22/05/2013 7:21:40 p.m. Entered internal PlaceOrder() method at 22/05/2013 7:21:40 p.m.: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=1670.25 StopPrice=0 SignalName='short1' FromEntrySignal=''

    22/05/2013 7:21:40 p.m. Cancelled pending entry order on opposite side of the market: BarsInProgress=0: Order='f3f5f320445145e7a07684ebaf0c15f3/Replay101' Name='short1' State=Working Instrument='ES 06-13' Action=SellShort Limit price=1670.25 Stop price=0 Quantity=1 Strategy='testfills' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='f3f5f320445145e7a07684ebaf0c15f3' Gtd='1/12/2099 12:00:00 a.m.'
    Thanks

    #2
    Hello daaim0,

    Thank you for your post.

    The item here is that your "pt" (I assume this is intended to be a Profit Target) is submitted as an EnterShortLimit(), so NinjaTrader treats this as a new position to take in the opposite direction. This first causes a short order to close your long position and then since the original entry is no longer valid the EnterShortLimit() is cancelled.

    As stated above I assume this is intended as a Profit Target, so I recommend the use of ExitLongLimit() in place of EnterShortLimit().
    Code:
    protected override void OnOrderUpdate(IOrder order)
    {
       if(long1 != null && long1 == order)
       {
          if(order.OrderState == OrderState.Filled)
          {
             [B]short1 = ExitLongLimit(0,true,1,pt,"short1", "long1"); [/B]
          }
    	
    }
    For information on ExitLongLimit() please visit the following link: http://www.ninjatrader.com/support/h...tlonglimit.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      Hi Patrick, thanks for your reply.

      In this example, you are correct when saying PT stands for profit target but my overall goal is to have two ENTER short limit orders working while going long. Essentially, I am trying to achieve a reversal using limits (first short limit will end the trade and the second limit will enter the market again).

      If I were to use ExitLongLimit simultaneously with EnterShortLimit, I assume that either NT won't allow that or due to the nature of limits, the enter limit may fill before exit long limit.

      By having two enter limits (plus something to handle partial fills), I hope to achieve the reversal but I am getting that issue I mentioned.

      If I understood correctly, you said that my first short order cancelled my long position but it didn't for me. Only the short limit was cancelled and another short limit was created.

      Thanks

      Comment


        #4
        Hello daaim0,

        Thank you for your response.

        With the use of the EnterShortLimit() you will be able to achieve the reversal as the EnterShortLimit() will close the Long position and enter short. However, you may wish to limit the submission of this order to when you wish to reverse because the submission of this order will close the long position.

        You may also wish to consider moving to the unmanaged approach for order methods: http://www.ninjatrader.com/support/h...d_approach.htm

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        634 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X