Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IOrder Advanced trades

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

    IOrder Advanced trades

    Do you have an example using the features of IOrder etc?
    I want to open a position with 2 contracts
    Once price hits a certain tick count close 1 position and move the other to lets say BE.

    #2
    Hello bbucha_stk,

    Thank you for your post.

    We have a reference sample on using the OnOrderUpdate() and OnExecution() methods in conjunction with IOrder that you can use to achieve this at the following link: http://www.ninjatrader.com/support/f...ead.php?t=7499

    Please let me know if you have any questions.

    Comment


      #3
      IOrder continued

      So I made following change
      protected override void OnBarUpdate()
      {
      // Submit an entry limit order if we currently don't have an entry order open
      if (entryOrder == null && Close[0] > Open[0])
      {
      /* The entryOrder object will take on a unique ID from our EnterLong()
      that we can use later for order identification purposes in the OnOrderUpdate() method. */
      entryOrder = EnterLong(2, "MyLong");
      }

      /* If we have a long position and the current price is 4 ticks in profit, raise the stop-loss order to breakeven.
      We use (7 * (TickSize / 2)) to denote 4 ticks because of potential precision issues with doubles. Under certain
      conditions (4 * TickSize) could end up being 3.9999 instead of 4 if the TickSize was 1. Using our method of determining
      4 ticks helps cope with the precision issue if it does arise. */
      if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + (7 * (TickSize / 2)))
      {
      // Checks to see if our Stop Order has been submitted already
      if (stopOrder != null && stopOrder.StopPrice < Position.AvgPrice)
      {
      //Exit one of positions and
      // Modifies stop-loss to breakeven on remaining position
      ExitLong(0, 1, "First Position Close", "MyLong");
      stopOrder = ExitLongStop(0, true, 1, Position.AvgPrice, "MyStop", "MyLong");
      }
      }
      }
      Is this how you would exit 1 position and move other position to BE?

      Comment


        #4
        Hello bbucha_stk,

        Thank you for your post.

        That is correct, you could exit one quantity and move the Stop to Breakeven with that method.

        Comment


          #5
          IOrder cont

          Hopefully one last question for clairity
          You state to set and adjust target and stop with "OnExecution" method
          Your example does not show shorts vs longs
          Do I use the Position to determine what direction I am in to set target and stops ????

          protected override void OnExecution(IExecution execution)
          {
          /* We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
          which ensures your strategy has received the execution which is used for internal signal tracking. */
          if (entryOrder != null && entryOrder == execution.Order)
          {
          if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
          {
          // Stop-Loss order 8 ticks below our entry price
          stopOrder = ExitLongStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - 8 * TickSize, "MyStop", "MyEntry");

          // Target order 23 ticks above our entry price
          targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 23 * TickSize, "MyTarget", "MyEntry");

          // Resets the entryOrder object to null after the order has been filled
          if (execution.Order.OrderState != OrderState.PartFilled)
          {
          entryOrder = null;
          }
          }
          }

          Comment


            #6
            Hello ,

            Thank you for your post.

            That is correct, you would use Position.MarketPosition to determine if you are long or short.

            For information on Position.MarketPosition please visit the following link: http://www.ninjatrader.com/support/h...etposition.htm

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

            Comment


              #7
              adding in Initialize()
              EntriesPerDirection = 2;
              Unmanaged = true;


              Window I get following :
              3/16/2011 07:22:25 System.Exception: 'EnterShort' method can't be called on unmanaged strategies.
              at NinjaTrader.Strategy.StrategyBase.EnterShort(Int32 quantity, String signalName)
              at NinjaTrader.Strategy.BobGoldStandardV21.OnBarUpdat e()

              Comment


                #8
                Originally posted by bbucha_stk View Post
                adding in Initialize()
                EntriesPerDirection = 2;
                Unmanaged = true;


                Window I get following :
                3/16/2011 07:22:25 System.Exception: 'EnterShort' method can't be called on unmanaged strategies.
                at NinjaTrader.Strategy.StrategyBase.EnterShort(Int32 quantity, String signalName)
                at NinjaTrader.Strategy.BobGoldStandardV21.OnBarUpdat e()
                It means what it says. You cannot mix unmanaged order methods with those for managed orders. Use the correct syntax. For unmanaged methods, you use SubmitOrder(). ref: http://www.ninjatrader.com/support/h...d_approach.htm

                Comment


                  #9
                  So whats happenning is I hit my 8 ticks and it closes the one position
                  and moves stop all is good.

                  But if I have for example a target of 20 ticks and it closes
                  The code is entering another position
                  Its like the target was hit and closed, but I am still thinking I am in a position and when I move the stop it enters another position.
                  If I put the target way out then it works as expected????

                  Comment


                    #10
                    Originally posted by bbucha_stk View Post
                    So whats happenning is I hit my 8 ticks and it closes the one position
                    and moves stop all is good.

                    But if I have for example a target of 20 ticks and it closes
                    The code is entering another position
                    Its like the target was hit and closed, but I am still thinking I am in a position and when I move the stop it enters another position.
                    If I put the target way out then it works as expected????
                    Hard to say without seeing your code. It depends on what you have coded. The system will simply follow what you have written. If the code is doing other than you intended, it just means that the code does not correctly depict what you intended. You will have to trace the logic to see where the code's action deviates from what you intended, then correct it as necessary.

                    Comment


                      #11
                      I am getting a call to OnOrderUpDate(Iorder ) from some unknown call???
                      Below is the object coming in.
                      The scenerio is as follows around 6am I enter 2 positions and around 6:15 the position is closed.
                      Then around 9am I get this call from no where....
                      I can provide the code if need be, but I am wondering if you have a suggestion for me to look at. I have visual studio debugger

                      - order {Order='70d34cabe7cd428586ede6fd759b5303/Replay101' Name='MyTarget' State=Filled Instrument='6E 06-11' Action=Sell Limit price=1.4222 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='' Filled=1 Fill price=1.4222 Token='70d34cabe7cd428586ede6fd759b5303' Gtd='1/1/0001 00:00:00'} NinjaTrader.Cbi.IOrder {NinjaTrader.Strategy.OrderProxy}
                      + [NinjaTrader.Strategy.OrderProxy] {Order='70d34cabe7cd428586ede6fd759b5303/Replay101' Name='MyTarget' State=Filled Instrument='6E 06-11' Action=Sell Limit price=1.4222 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='' Filled=1 Fill price=1.4222 Token='70d34cabe7cd428586ede6fd759b5303' Gtd='1/1/0001 00:00:00'} NinjaTrader.Strategy.OrderProxy
                      AvgFillPrice 1.4222 double
                      Error NoError NinjaTrader.Cbi.ErrorCode
                      Filled 1 int
                      FromEntrySignal "MyLongEntry" string
                      + Instrument {6E 06-11 Globex} NinjaTrader.Cbi.Instrument
                      LimitPrice 1.4222 double
                      LiveUntilCancelled true bool
                      Name "MyTarget" string
                      NativeError "" string
                      Oco "" string
                      OrderAction Sell NinjaTrader.Cbi.OrderAction
                      OrderId "70d34cabe7cd428586ede6fd759b5303" string
                      OrderState Filled NinjaTrader.Cbi.OrderState
                      OrderType Limit NinjaTrader.Cbi.OrderType
                      OverFill false bool
                      Quantity 1 int
                      StopPrice 0.0 double
                      + Time {5/16/2011 08:54:18} System.DateTime
                      TimeInForce Gtc NinjaTrader.Cbi.TimeInForce
                      Token "70d34cabe7cd428586ede6fd759b5303" string

                      Comment


                        #12
                        Hello bbucha_stk,

                        Thank you for your note.

                        This is your Profit Target filling as indicated by the order state.
                        OrderState Filled NinjaTrader.Cbi.OrderState
                        You can keep track of your orders through the Output Window by enabling TraceOrders in your strategy: http://www.ninjatrader.com/support/f...ead.php?t=3627

                        I also recommend reviewing the following link for information on debugging your NinjaScript code: http://www.ninjatrader.com/support/f...ead.php?t=3418

                        Please let me know if you have any questions.

                        Comment


                          #13
                          I will try tracing and see if it helps narrow down the issue.
                          Note : It appears to me that I opened 2 positions and met and closed them.

                          Then 2 hrs later all of a sudden then update fires as I sent to you in above post.

                          Comment


                            #14
                            Hello bbucha_stk,

                            Thank you for your update.

                            Please let me know if you have any questions as you debug your NinjaScript code.

                            Comment


                              #15
                              The following is the trace order....
                              Look at bottom that I marked in RED not sure what this means as I should of been FLAT ???
                              5/16/2011 06:03:31 Entered internal PlaceOrder() method at 5/16/2011 06:03:31: BarsInProgress=0 Action=Buy OrderType=Market Quantity=2 LimitPrice=0 StopPrice=0 SignalName='MyLongEntry' FromEntrySignal=''
                              5/16/2011 06:03:31Plan A Long
                              5/16/2011 06:03:31 Entered internal PlaceOrder() method at 5/16/2011 06:03:31: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=2 LimitPrice=0 StopPrice=1.4096 SignalName='MyStop' FromEntrySignal='MyLongEntry'
                              5/16/2011 06:03:31 Entered internal PlaceOrder() method at 5/16/2011 06:03:31: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=2 LimitPrice=1.4222 StopPrice=0 SignalName='MyTarget' FromEntrySignal='MyLongEntry'
                              5/16/2011 06:09:32 Entered internal PlaceOrder() method at 5/16/2011 06:09:32: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='First Position Close' FromEntrySignal='MyLongEntry'
                              5/16/2011 06:09:32 Entered internal PlaceOrder() method at 5/16/2011 06:09:32: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.4122 SignalName='MyStop' FromEntrySignal='MyLongEntry'
                              5/16/2011 06:09:32 Amended matching order: Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.4122 SignalName=MyStop' FromEntrySignal='MyLongEntry'
                              5/16/2011 06:18:11 Entered internal PlaceOrder() method at 5/16/2011 06:18:11: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.4130 SignalName='MyStop' FromEntrySignal='MyLongEntry'
                              5/16/2011 06:18:11 Amended matching order: Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1.4130 SignalName=MyStop' FromEntrySignal='MyLongEntry'
                              5/16/2011 06:25:37 Amended pending exit order, since associated position is closed: Order='4521bf4104724c3fb2c58bd72a418a1b/Replay101' Name='MyTarget' State=Working Instrument='6E 06-11' Action=Sell Limit price=1.4222 Stop price=0 Quantity=2 Strategy='BobGoldStandardV21' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4521bf4104724c3fb2c58bd72a418a1b' Gtd='12/1/2099 00:00:00'

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 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