Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

NT's Internal Order Handling Issue?

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

    NT's Internal Order Handling Issue?

    Guys,

    I have a strategy that onBarUpdate() determines the market position before trading so as to exit any opposite position first. However, during a backtest a long trade was ignored because a short was open, or so I believe. Here's the trace order output:

    3/17/2009 1:23:00 AM Entered internal PlaceOrder() method at 3/17/2009 1:23:00 AM: Action=Buy OrderType=Limit Quantity=0.02M LimitPrice=1.3014 StopPrice=0 SignalName='LongX' FromEntrySignal=''
    3/17/2009 1:23:00 AM Ignored PlaceOrder() method at 3/17/2009 1:23:00 AM: Action=Buy OrderType=Limit Quantity=0.02M LimitPrice=1.3014 StopPrice=0 SignalName=LongX' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignore. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.'


    My OnBarUpdate() code is this:
    if (Position.MarketPosition == MarketPosition.Short) {
    if (someCondition) // long entry signal
    {
    exitOrder = ExitShort(Position.Quantity, "XShrtOnLongX", "ShortX");
    if (stopOrder != null)
    CancelOrder(stopOrder);
    entryOrder = EnterLongLimit(simLotsTraded, GetCurrentBid(), "LongX");


    As you can see, it should exit before entering and ususally does. However this time it did not. How can I deal with this?
    Attached Files

    #2
    crmcwi, please try entering code to confirm the order reached indeed 'cancelled' state (confirmed) before you place the opposing order.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      while loop?

      Good idea Bertrand, but let me ask you something that only an experienced NT coder would know.

      Can I or should I use a while() loop to wait for the cancelling?

      In pseudo code, it might be something like:

      While (stopOrder.OrderState != OrderState.Cancelled) {
      do something like increment a counter;
      }

      the reason I ask is becuase I thought NT should do this in the background and if this should typically be done, it should be documented, yes?
      Last edited by crmcwi; 09-25-2009, 06:39 AM. Reason: forgot something

      Comment


        #4
        I don't think you would need a loop for this, as it's all event based - just make sure you received the confirmed cancelled orderstate - this is also a good preparation to take the strategy live as order confirmations would take a bit longer in real life than possibly on the internal Sim101.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Ok, thanks Bertrand,

          But I'm still confused. My code goes like this:

          ExitOrder = .....
          if stopOrder !=null, cancelOrder (stopOrder)

          EntryOrder = ....


          the problem is that the EntryOrder is ignored because the stop order exitorder isn't filled.

          If I just put a condition to the EntryOrder = , won't the code just process the condition, calculate that the stopOrder is not null, and then proceed past the EntryOrder? In other words, don't I have to make the code wait for the stopOrder to be filled?

          Comment


            #6
            You want to wait for the fill confirmation in the OnOrderUpdate(), this way you know it's updated / received before you issue your following entry.

            The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()
            BertrandNinjaTrader Customer Service

            Comment


              #7
              aha.

              Ok, so the EntryOrder = ... for this situation has to go in OnOrderUpdate()? Yikes.

              this has some far reaching ramifications for anytime one wishes to enter two orders successively as in OCO situations.

              Comment


                #8
                aha.

                Ok, so the EntryOrder = ... for this situation has to go in OnOrderUpdate()? Yikes.

                this has some far reaching ramifications for anytime one wishes to enter two orders successively as in OCO situations.

                Comment


                  #9
                  crmcwi,

                  Not sure what ramifications you are referring to. All you need to do in OnOrderUpdate() is check for a partial filled or filled state for your entry order. Then you can place your exit orders at the correct time. Placing an exit order before you even have an entry position will result in ignored exit orders.
                  Josh P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by cre8able, Yesterday, 09:15 PM
                  2 responses
                  13 views
                  0 likes
                  Last Post cre8able  
                  Started by Trader146, Today, 09:17 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post Trader146  
                  Started by ttrader23, 05-08-2024, 09:04 AM
                  9 responses
                  43 views
                  0 likes
                  Last Post ttrader23  
                  Started by ZeroKuhl, Yesterday, 04:31 PM
                  8 responses
                  46 views
                  0 likes
                  Last Post ZeroKuhl  
                  Started by reynoldsn, Today, 07:04 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post reynoldsn  
                  Working...
                  X