Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy error in Log -- what is it?

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

    Strategy error in Log -- what is it?

    When running a strategy in real-time on a live feed, I have the strategy attempt to cancel a previously entered order if it is in an Accepted or Working state, like this:

    Print("myEntryLong = " + myEntryLong);
    if (myEntryLong != null && (myEntryLong.OrderState == OrderState.Working || myEntryLong.OrderState == OrderState.Accepted)) // Cancel previous stop order if it exists
    {
    Print(Instrument.MasterInstrument.Name + " - Canceling previous long stop order at " + myEntryLong.StopPrice);
    CancelOrder(myEntryLong); // Cancel previous long stop order
    Print(Instrument.MasterInstrument.Name + " " + myEntryLong.StopPrice + " cancelled.");
    }

    And in the OnOrderUpdate() tag I have this code:

    Print(Instrument.MasterInstrument.Name + " - " + order.Name + " order " + order.OrderState);
    if (order.OrderState == OrderState.Filled)
    {
    myEntryLong = null;
    }


    But (only sometimes!?) when this code executes, I get this error in the Log tab:

    Cbi.Order.Cancel: exception caught: Value cannot be null.

    Do you know what this error means, and how to debug it? I'm stumped, and I have the debug "Print" lines in there to try to help, but it's not helping.

    Thanks!
    Bryan

    #2
    - please make sure you are on latest 6.5.1000.1
    - could you create a simple as possible scenario (strategy + settings) in order to reproduce?

    Thanks

    Comment


      #3
      Yes, I am on that version.

      I will try to reproduce, although the strategy is pretty simple already. All I want to do is cancel a previously placed stop order and place a new stop order at a different price. Let me see if I can create a new strategy to just do that whenever the bar is updated.

      Also... do you know what that error means, and what part of the code is producing it? The strategy compiles fine (obviously), so this is a run-time bug -- not sure how to debug that unless I can step through the code as it executes.

      Thanks!
      Bryan

      Comment


        #4
        Maybe this is it. I'm setting the IOrder object to null when the order is in a OrderState.Filled state. How else can I determine when an order object is no longer 'active?' Like, what property of IOrder can I check to see when a filled order is no longer working and has either been stopped out or the target reached?

        Comment


          #5
          Not sure, but you should not change the IOrder object.

          IOrder should have an OrderState property to check on.

          Comment


            #6
            Originally posted by NinjaTrader_Dierk View Post
            Not sure, but you should not change the IOrder object.

            IOrder should have an OrderState property to check on.

            Check the Help Guide -- it has an example that I copied to my strategy where it sets the IOrder object to null:



            protected override void OnOrderUpdate(IOrder order)
            {
            if (entryOrder != null && entryOrder.Token == order.Token)
            {
            Print(order.ToString());
            if (order.OrderState == OrderState.Filled)
            entryOrder = null;
            }
            }



            Which OrderState property tells me when an order was filled and then closed after a stop or target was hit?

            Also... WHAT DOES THAT ERROR MESSAGE MEAN?
            Last edited by cassb; 04-23-2008, 09:12 AM.

            Comment


              #7
              Not sure I follow.
              order.OrderState == OrderState.Filled
              ... tells you as an order is filled.

              Comment


                #8
                When an order is filled, it is still active until closed. I don't think you can place another stop order with the same name (myEntryLong in this case) when there is an active order with that name.

                Maybe this will help:

                What I'm trying to do is place a stop order at a certain price. There are two things that can happen then:

                1) The stop order is filled and subsequently closed.
                2) Market conditions change so that I want to cancel the stop order and place a new one at a different price.
                Last edited by cassb; 04-23-2008, 09:16 AM.

                Comment


                  #9
                  Not sure I follow. May be you should drive your logic on the ExecutionUpdate events...

                  Comment


                    #10
                    Originally posted by NinjaTrader_Dierk View Post
                    Not sure I follow. May be you should drive your logic on the ExecutionUpdate events...
                    Maybe this will help:

                    What I'm trying to do is place a stop order at a certain price. There are two things that can happen then:

                    1) The stop order is filled and subsequently closed.
                    2) Market conditions change so that I want to cancel the stop order and place a new one at a different price.

                    Comment


                      #11
                      My strategy works fine except when that error occurs. I need to know what that error message means, and how it's being generated. Can Ray help me?

                      Comment


                        #12
                        This is in the NT core. We would need to know how to reproduce. Please see my post below. Thanks

                        Comment


                          #13
                          OK, I can reproduce it now. How do I send you the strategy file?

                          Thanks,
                          Bryan

                          Comment


                            #14
                            Please send the strategy and any relevant settings (screenshot of properties dialog?) to "dierk AT ninjatrader DOT com". Thanks

                            Comment


                              #15
                              Originally posted by NinjaTrader_Dierk View Post
                              Please send the strategy and any relevant settings (screenshot of properties dialog?) to "dierk AT ninjatrader DOT com". Thanks
                              I mean, how do I save the strategy code to a file so I can send it to you?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              671 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X