Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Information

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

    Order Information

    Hi,

    I am trying to understand how to properly modify a stop order to execute on a trailing stop value. I am using the following code.

    Code:
     
    case MarketPosition.Short: // === OPEN SHORT POSITION
    // ... retrieve the current value of the trailing stop
    trailValue = TrailDown.TrailStop[0];
     
    // ... we have an open short position; modify the stop loss value as per the trailing stop
    if (High[0] < trailValue)
    {
    // ... check to see if the stop order for the open short position has been submitted already
    if (stopOrder != null && stopOrder.StopPrice > trailValue)
    {
    // ... modify the stop loss to the new value of the trailing stop
    stopOrder = ExitShortStop(0, true, stopOrder.Quantity, trailValue, "ShortStop", "ShortEntry");
    }
    }
    break;
    I do not understand the information I receive, namely

    7/27/2014 7:05:00 PM Entered internal PlaceOrder() method at 7/27/2014 7:05:00 PM: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1138.0 SignalName='ShortStop' FromEntrySignal='ShortEntry'

    7/27/2014 7:05:00 PM Amended open order: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1138.0 SignalName=ShortStop' FromEntrySignal='ShortEntry'

    Can someone please explain whether this is "normal"? I would think the first statement - the place order - would be sufficient so why the amend when there is no amendment of the stop price taking place?

    Thank you for any clarification/explanation you provide.

    #2
    Hello Zeos6,

    Thank you for your post.

    Is the information you provide from the initial placement of the ShortStop or when it is adjusted to the new price?

    Comment


      #3
      Hi PatrickH,

      The order is placed at 6:55

      ===
      trailValue = 1138.6

      7/27/2014 6:55:00 PM Entered internal PlaceOrder() method at 7/27/2014 6:55:00 PM: BarsInProgress=0 Action=SellShort OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1136.9 SignalName='ShortEntry' FromEntrySignal=''
      entryOrder = Order='NT-00000/Backtest' Name='ShortEntry' State=PendingSubmit Instrument='TF 09-14' Action=SellShort Limit price=0 Stop price=1136.9 Quantity=1 Strategy='PB_TrailStopStrategy' Type=Stop Tif=Day Oco='' Filled=0 Fill price=0 Token='9d84a7869a194c8d80fe8162ae2ea28b' Gtd='12/1/2099 12:00:00 AM'
      ===

      but it does not trigger on the next bar, 7:00, because the conditions have not been met

      ===
      Position.MarketPosition = Flat
      shortTrailExists = True

      entryOrder = Order='NT-00000/Backtest' Name='ShortEntry' State=Working Instrument='TF 09-14' Action=SellShort Limit price=0 Stop price=1136.9 Quantity=1 Strategy='PB_TrailStopStrategy' Type=Stop Tif=Day Oco='' Filled=0 Fill price=0 Token='9d84a7869a194c8d80fe8162ae2ea28b' Gtd='12/1/2099 12:00:00 AM'
      ===

      so when the conditions are met at 7:05 it actual triggers with the two lines

      ===
      Position.MarketPosition = Short

      7/27/2014 7:05:00 PM Entered internal PlaceOrder() method at 7/27/2014 7:05:00 PM: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1138.0 SignalName='ShortStop' FromEntrySignal='ShortEntry'

      7/27/2014 7:05:00 PM Amended open order: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1138.0 SignalName=ShortStop' FromEntrySignal='ShortEntry'
      ===


      Incidentally, the exit is a bit strange as well. It is trailing at 7:05 and exits at 7:10.

      ===
      Strategy Time[0] = 7/27/2014 7:05:00 PM
      Position.MarketPosition = Short

      7/27/2014 7:05:00 PM Entered internal PlaceOrder() method at 7/27/2014 7:05:00 PM: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1138.0 SignalName='ShortStop' FromEntrySignal='ShortEntry'

      7/27/2014 7:05:00 PM Amended open order: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1138.0 SignalName=ShortStop' FromEntrySignal='ShortEntry'
      ===

      The final exit from the position is at 7:10.

      ===
      Strategy Time[0] = 7/27/2014 7:10:00 PM
      Position.MarketPosition = Short

      7/27/2014 7:10:00 PM Entered internal PlaceOrder() method at 7/27/2014 7:10:00 PM: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1137.9 SignalName='ShortStop' FromEntrySignal='ShortEntry'

      7/27/2014 7:10:00 PM Amended open order: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1137.9 SignalName=ShortStop' FromEntrySignal='ShortEntry'
      ===

      I do not understand the placement and then the amendment. I think I am trailing the market correctly but clearly I lack understanding something important here. Can you please explain? Thank you.
      Last edited by Zeos6; 08-13-2014, 12:25 PM.

      Comment


        #4
        Hello Zeos6,

        Thank you for your response.

        What is the code for the initial placement of the stopOrder?

        Comment


          #5
          Hi PatrickH,

          The order is placed in the OnBarUpdate() section as follows:

          Code:
           
          case MarketPosition.Flat: // === FLAT POSITION (i.e. no open position)
          // === LOOK FOR ENTRY ===
          // .. check if we have the start of a short position trail; if yes, retrieve the short position trail stop value
          bool shortTrailExists = TrailDown.TrailStop.ContainsValue(0);
          if (shortTrailExists)
          trailValue = TrailDown.TrailStop[0];
          if (shortTrailExists && !longTrailExists && entryOrder == null)
          {
          /*
          The entryOrder object will take on a unique ID from our EnterShortStop() order
          that we can use later for order identification purposes in the OnOrderUpdate() method.
          */ 
          // .... set up a short entry
          barNumberOfOrder = CurrentBar;
          double entryPrice = Low[0]-5*TickSize;
          entryOrder = EnterShortStop(0, true, DefaultQuantity, entryPrice, "ShortEntry");
           
          DrawDot(""+index++, false, 0, entryPrice, Color.Plum);
          }
          // === CANCEL ENTRY ORDER ===
           
          // If an entryOrder exists and has not been filled within cancelBars number of bars,
          // cancel the entry order.
          if (entryOrder != null && CurrentBar > (barNumberOfOrder + cancelBars))
          CancelOrder(entryOrder);
          break;
          Thank you for your help.

          Comment


            #6
            Hello Zeos6,

            Thank you for your response.

            Amendments should occur to existing orders. Is the IOrder object stopOrder placed anywhere before the code from your original post?

            Comment


              #7
              Hi PatrickH,

              The short answer to your question

              Is the IOrder object stopOrder placed anywhere before the code from your original post?
              is no. That is why this is baffling me so much. Clearly I am lacking in understanding. Thank you.

              Comment


                #8
                Hello Zeos6,

                Thank you for your response.

                Unfortunately, I am unaware as to why it is doing this as well. Do you have a testable strategy that recreates the same item that I could test on my end?

                Comment


                  #9
                  Hi PatrickH,

                  Yes. I have a testable strategy. I would be happy to email it it to you if you let me know how. Thank you.

                  Comment


                    #10
                    Hello Zeos6,

                    Thanks for your reply.

                    Please send this to platformsupport[at]ninjatrader[dot]com and include a link to this forum topic.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    647 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    369 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    108 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    572 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    573 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X