Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLong/Short() "feature" (bug)???

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

    EnterLong/Short() "feature" (bug)???

    Hello,

    In my code, I do the following:
    Global Vars
    -----------
    private string _entrySignalName = null;
    private string _stopSignalName = null;

    ...

    // Set the signal Entry Order Signal Name
    _entrySignalName = "SELL " + _orderQuantity.ToString() + " @ " + entryPrice.ToString();
    // Send a Market Order
    _entryOrder = EnterShort( _PrimaryBars, _orderQuantity, _entrySignalName );

    ...

    // Set the Stop Order signal name
    _stopSignalName = "Trailing_Stop";

    // Now set the Trailing stop
    _stopOrder = ExitLongStop( _PrimaryBars, true, _stopOrder.Quantity, stopPrice, _stopSignalName, _entrySignalName );

    Nothing wrong so far, untill I realised that my Trailing Stops were not being executed. A trace through the program reveals the following:

    When created, this is what the "_entryOrder" has as properties:

    Action : SellShort
    AvgFillPrice : 98.26
    Filled : 1
    FromEntrySignal : ""
    Instrument : {$USDJPY Default}
    LimitPrice : 0.0
    LiveUntilCancelled : false
    Name : "SELL 1 @ 98.27"
    Oco : ""
    ...

    Clearly the property 'FromEntrySignal' which should equal my 'entrySignalName' is not, instead, the 'Name' property has the 'entrySignalName' value !!!!

    So, my "ExitLongStop()" calls are not tied to any "Entry Order"!!!

    How do I solve this unexplained 'feature'?

    Cheers,
    Obi

    #2
    _entryOrder is an entry. There is no "fromEntrySignal" for an entry order. There is only a signal name for that order. Then on your exit order you tie it to your entry order by placing in the entry order's signal name into the exit order's fromEntrySignal.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      This is what I suposedly did:

      EnterLong(int barsInProgressIndex, int quantity, string signalName)

      // Send a Market Order
      _entryOrder = EnterShort( _PrimaryBars, _orderQuantity, _entrySignalName );


      >> "Then on your exit order you tie it to your entry order by placing in the entry order's
      >> signal name into the exit order's fromEntrySignal. "

      My exit order has "entrySignalName" to tie it to the entry order:
      ExitShort(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal)


      // Now set the Trailing stop
      _stopOrder = ExitLongStop( _PrimaryBars, true, _stopOrder.Quantity, stopPrice, _stopSignalName, _entrySignalName );

      Is the above not correct?


      >> "There is no "fromEntrySignal" for an entry order."

      I don't know how to attach an image to this post. So I typed in the values of the entry order from the debugger's view.
      And there, it shows both the 'Name' and 'FromEntrySignal' fields. Of course, since the entry order is of type IOrder and an IOrder has both fields.

      It could be that only one of the fields is used (also, as shown by the debugger).

      Comment


        #4
        Correct. You should use TraceOrders = true to see what is happening to your exit order.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          I have that set already. What do I do now? where do I look and what exactly am I looking for? What should it say?

          Cheers,
          Obi

          Comment


            #6
            Look in the Output Window and read the messages for the order that you feel is not being submitted.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              09/06/2009 04:30:02 Ignored PlaceOrder() method: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=98.40'5 SignalName='Initial_Stop' FromEntrySignal='SELL 1 @ 98.27'
              Reason='This was an exit order but no position exists to exit'

              But we know there is position to exit/cover.
              This tells me that the Stop order could not be tied to an entry order as we discussed earlier. Sending me back to square one.

              What do I do now?

              Comment


                #8
                Please paste full output of the whole sequence of events along with actual code.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Order of events:

                  YM: *********** Started @ 2009-06-08 12:09 *********
                  08/06/2009 13:55:10 Entered internal PlaceOrder() method at 08/06/2009 13:55:10: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='SELL 1 @ 8685' FromEntrySignal=''

                  08/06/2009 13:55:11 Entered internal PlaceOrder() method at 08/06/2009 13:55:11: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=8694 SignalName='Initial_Stop' FromEntrySignal='SELL 1 @ 8685'

                  08/06/2009 13:55:11 Ignored PlaceOrder() method: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=8694 SignalName='Initial_Stop' FromEntrySignal='SELL 1 @ 8685' Reason='This was an exit order but no position exists to exit'

                  ***** E N T R Y O R D E R F I L L E D *****

                  09/06/2009 04:30:02 Entered internal PlaceOrder() method at 09/06/2009 04:30:02: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='SELL 1 @ 98.27' FromEntrySignal=''

                  09/06/2009 04:30:02 Entered internal PlaceOrder() method at 09/06/2009 04:30:02: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=98.40'5 SignalName='Initial_Stop' FromEntrySignal='SELL 1 @ 98.27'

                  09/06/2009 04:30:02 Ignored PlaceOrder() method: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=98.40'5 SignalName='Initial_Stop' FromEntrySignal='SELL 1 @ 98.27' Reason='This was an exit order but no position exists to exit'


                  source code:
                  ---------------

                  if ( marketDir == _Short )
                  {
                  // Set the signal Entry Order Signal Name
                  _entrySignalName =
                  "SELL " + _orderQuantity.ToString() + " @ " + entryPrice.ToString();

                  // Send a Market Order
                  _entryOrder =
                  EnterShort( _PrimaryBars, _orderQuantity, _entrySignalName );


                  // Set the Initial Stop order SignalName
                  _stopSignalName = "Initial_Stop";

                  _stopOrder = ExitShortStop( _PrimaryBars, true,
                  Position.Quantity, stopPrice, _stopSignalName, _entrySignalName );

                  ...

                  // Set the Trailing Stop Order signal name
                  _stopSignalName = "Trailing_Stop";

                  // Now set the Trailing stop
                  _stopOrder = ExitShortStop( _PrimaryBars, true,
                  _stopOrder.Quantity, stopPrice, _stopSignalName, _entrySignalName );

                  ...

                  }

                  Comment


                    #10
                    Add prints to OnOrderUpdate() method and track the order status of the events coming in from there to see if some orders are getting filled.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Done already, and none is shown. Here is the code:

                      protected override void OnOrderUpdate( IOrder order )
                      {
                      if ( (_stopOrder != null) && (_stopOrder.Token == order.Token) )
                      {
                      if (order.OrderState == OrderState.Filled)
                      {
                      Print(" ***** S T O P O R D E R F I L L E D *****");
                      }
                      else if (order.OrderState == OrderState.Cancelled)
                      {
                      Print(" ***** S T O P O R D E R C A N C E L L E D *****");
                      }
                      else if (order.OrderState == OrderState.Rejected)
                      {
                      Print(" <><><><><> S T O P O R D E R R E J E C T E D <><><><><>");
                      Print( "Order Time : " + order.Time.ToString() );
                      Print( "Order Instrument : " + order.Instrument.ToString() );
                      Print( "Order Type : " + order.OrderType.ToString() );
                      Print( "Order Action : " + order.Action.ToString() );
                      }
                      }

                      if ( (_entryOrder != null) && (_entryOrder.Token == order.Token) )
                      {
                      if ( order.OrderState == OrderState.Filled )
                      {
                      Print(" ***** E N T R Y O R D E R F I L L E D *****");
                      }
                      else if ( order.OrderState == OrderState.Rejected )
                      {
                      Print(" <><><><><> E N T R Y O R D E R R E J E C T E D <><><><><>");
                      Print( "Order Time : " + order.Time.ToString() );
                      Print( "Order Instrument : " + order.Instrument.ToString() );
                      Print( "Order Action : " + order.Action.ToString() );
                      }
                      }
                      }

                      Comment


                        #12
                        Then the mystery is now solved. You are submitting your ExitShortStop() before you even get a fill on your entry order. When there is no fill there is no position and as such the Exit order will be ignored since there is nothing to exit at that point in time.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Er .... I follow you, but I don't see how I'm doing it since the stop order is sent after the entry order.
                          Am I missing something?

                          Comment


                            #14
                            Yes. From your Output it is clear you submitted it, but it is also clear that the order was not filled yet. It takes time for an order to fill and you have to compensate for it. You can't just submit entry and exit one after the other like you are doing right now. You can only submit the exits after the entry has filled.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Gotcha. Thanks for the patience of working through this with me; absolutely great.

                              This means, one way of preventing the wrong orders submission will be to check something in the line of:

                              // Assuming that the entry order is reset to null when position is flat
                              if ( _entryOrder != null )
                              {
                              _stopOrder = ExitShort( ... );
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by DayTradingDEMON, Today, 09:28 AM
                              4 responses
                              21 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by geddyisodin, Yesterday, 05:20 AM
                              9 responses
                              50 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by George21, Today, 10:07 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Started by Stanfillirenfro, Today, 07:23 AM
                              9 responses
                              24 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by navyguy06, Today, 09:28 AM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X