Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue w/ExitLongLimit and ExitShortLimit

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

    Issue w/ExitLongLimit and ExitShortLimit

    Hi guys. I'm having trouble exiting an order.

    In OnBarUpdate I have the following type of code:

    if (long conditions are met)
    {
    MyEntryOrder = EnterLongLimit(0, true, 1, longprice, "long limit order");
    }

    Simple profit & stop orders are placed:

    stopOrder = ExitLongStop(0, true, 1, execution.Price - (10 * TickSize), "stop order", "long limit order");
    targetOrder = ExitLongLimit(0, true, 1, execution.Price + (5 * TickSize), "target order", "long limit order");


    Then I check for the appropriate instrument in each subsequent onBarUpdate calls:

    if (BarsInProgress != 0)
    return;

    If it is the bar of the appropriate instrument, and 10 minutes have passed since entry, I issue an exit order:

    if (BarsSinceEntry(0,"long limit order",0) > 10)
    {
    exitOrder = ExitLongLimit(0, true, 1, GetCurrentBid(), "long limit order exit", "long limit order");

    }

    When I run the script, it places the long order at an appropriate time as well as a stop order (Control Panel shows it in an ACCEPTED state) and a limit target order (Control Panel shows it in a WORKING state). If it lasts more than 10 bars, it issues the following error when the exit line is called:

    Object reference not set to an instance of an object.

    The same thing happens if I replace "long limit order" with the signal name of the target order ("target order"). If I put a call to ExitLongStop with the signal "stop order" I get the same result as well.

    Do you have any advice or links which say how to properly issue exit statements in an automated strategy?
    Last edited by JayJoshi; 04-07-2011, 06:22 PM.

    #2
    Have you declared exitOrder anywhere?

    Comment


      #3
      JayJoshi, in addition to koganam's remark: are you proper checking for null whenever accessing your IOrder object references?

      BertrandNinjaTrader Customer Service

      Comment


        #4
        Yes koganam - I've declared it as a class-level object:

        private IOrder exitOrder = null;
        Last edited by JayJoshi; 04-07-2011, 06:23 PM.

        Comment


          #5
          Hi Bertrand. I added in null reference checks and they uncovered one problem. I had a PRINT statement after the exit statement as follows:

          Print ("EXITING LONG LIMIT ORDER: " + exitOrder.ToString());

          Apparently exitOrder is NULL even after calling exitLongLimit() in a seemingly successful way.

          I added exitStopOrder & exitLimitOrder for the STOP/TARGET orders as well but am not getting any love. A reversal order isn't placed and the STOP/TARGET are both still live orders.

          Could the problem be that the base LIMIT order is filled, and that the STOP order is in an ACCEPTED state and TARGET is in a WORKING state? Do they need to be cancelled instead? If so, then how would I place a reverse order?

          Comment


            #6
            Originally posted by JayJoshi View Post
            Hi Bertrand. I added in null reference checks and they uncovered one problem. I had a PRINT statement after the exit statement as follows:

            Print ("EXITING LONG LIMIT ORDER: " + exitOrder.ToString());

            Apparently exitOrder is NULL even after calling exitLongLimit() in a seemingly successful way.

            I added exitStopOrder & exitLimitOrder for the STOP/TARGET orders as well but am not getting any love. A reversal order isn't placed and the STOP/TARGET are both still live orders.

            Could the problem be that the base LIMIT order is filled, and that the STOP order is in an ACCEPTED state and TARGET is in a WORKING state? Do they need to be cancelled instead? If so, then how would I place a reverse order?
            This is sounding more and more like the problem that I am having reversing with a limit order. Try turning on TraceOrders and see if that helps you see what is going on. So far, I have still not been able to figure it out either. I sure hope that someone can.

            Reversing with market orders is easy enough, but I have a deep seated fear of market orders, and avoid them unless absolutely necessary because I MUST get out NOW (for example, if only a few seconds are left to some economic numbers release, and I forgot to get out early enough).

            Comment


              #7
              JayJoshi,

              You should add TraceOrders = true; to your Initialize() method, and track messages related to strategy submission in the Tools > Output Window

              It sounds like you may be running into Internal Order Handling Rules that Reduce Unwanted Positions


              Methods that generate orders to enter a position will be ignored if:
              • A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Here is the output of TraceOrder. It looks like the problem is that we're trying to exit out of ExitOrders, and the signal name from the ExitLongLimit ('target order') and ExitLongStop ('stop order') are not being accepted as EntrySignals. Additionally 'long limit order' was filled.

                Our overall goal here is to exit the long position with a limit order at the current ask, if 10 minutes pass. We want to override the existing stop/target order. What is the best way to do this? Is there a way to modify the stop or target order price to the current ask, since they are in working/accepted states?

                The TraceOrder output:

                4/4/2011 9:00:06 AM Entered internal PlaceOrder() method at 4/4/2011 9:00:06 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=1.4221 StopPrice=0 SignalName='long limit order' FromEntrySignal=''

                4/4/2011 9:00:06 AM Entered internal PlaceOrder() method at 4/4/2011 9:00:06 AM: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.4209 SignalName='stop order' FromEntrySignal='long limit order'

                4/4/2011 9:00:06 AM Entered internal PlaceOrder() method at 4/4/2011 9:00:06 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=1.4224 StopPrice=0 SignalName='target order' FromEntrySignal='long limit order'

                --

                4/4/2011 9:02:01 AM Ignored PlaceOrder() method at 4/4/2011 9:02:01 AM: Action=Sell OrderType=Limit Quantity=0 LimitPrice=1.4220 StopPrice=0 SignalName='exit target' FromEntrySignal='long limit order' Reason='There is no remaining quantity to exit'
                targetOrder != null longs

                ---
                4/4/2011 9:02:01 AM Entered internal PlaceOrder() method at 4/4/2011 9:02:01 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=1.4220 StopPrice=0 SignalName='exit target' FromEntrySignal='target order'

                4/4/2011 9:02:01 AM Ignored PlaceOrder() method at 4/4/2011 9:02:01 AM: Action=Sell OrderType=Limit Quantity=1 LimitPrice=1.4220 StopPrice=0 SignalName='exit target' FromEntrySignal='target order' Reason='SignalName does not have a matching FromEntrySignal to exit'

                --

                4/4/2011 9:02:01 AM Entered internal PlaceOrder() method at 4/4/2011 9:02:01 AM: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.4220 SignalName='exit stop' FromEntrySignal='stop order'

                4/4/2011 9:02:01 AM Ignored PlaceOrder() method at 4/4/2011 9:02:01 AM: Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.4220 SignalName='exit stop' FromEntrySignal='stop order' Reason='SignalName does not have a matching FromEntrySignal to exit'

                Comment


                  #9
                  JayJoshi, please try canceling your exit orders and then immediately submitting the limit exit order.
                  AustinNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by rdtdale, Yesterday, 01:02 PM
                  2 responses
                  16 views
                  0 likes
                  Last Post rdtdale
                  by rdtdale
                   
                  Started by TradeSaber, Today, 07:18 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post TradeSaber  
                  Started by PaulMohn, Today, 05:00 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post PaulMohn  
                  Started by ZenCortexAuCost, Today, 04:24 AM
                  0 responses
                  6 views
                  0 likes
                  Last Post ZenCortexAuCost  
                  Started by ZenCortexAuCost, Today, 04:22 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post ZenCortexAuCost  
                  Working...
                  X