Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using OnOrderUpdate()

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

    #16
    Originally posted by NinjaTrader_Ray View Post
    Yes that's fine, the breaking is likely a logic issue which you need to debug.

    hehe... i guess i needed to learn that variable names that pass to objects aren't merely able to be .toStringed(). The better question -- does a CancelOrder(iorder variable object) actually null out the variable after it runs the cancel?

    since i can't visualize the variable with a print statement, I figure its worth asking you.

    The debug output seems to make it appear that maybe all of this treatment is unnecessary. Maybe cancelorder is enough (and variable = null is already done).

    Comment


      #17
      No, it will not be set to null. The variable will hold its object until you set it otherwise.

      You can print out any property on an IOrder object you want:

      Print(myOrder.Token + " " myOrder.OrderState);

      etc...
      RayNinjaTrader Customer Service

      Comment


        #18
        interesting. so if I change an iOrder variable, and it runs, what is the purpose of nulling the variable (since it won't be called again), in the case of a stoploss ? [for an entry it makes sense, since I can have logic to see if entry is null or not before I enter a new trade...]

        Comment


          #19
          Please take a look at the reference sample at the link provided for an idea how setting the variable to null may be of value.
          RayNinjaTrader Customer Service

          Comment


            #20
            Originally posted by NinjaTrader_Ray View Post
            Please take a look at the reference sample at the link provided for an idea how setting the variable to null may be of value.
            Thanks for all the help. I originally started my work by taking from that very sample (select bits to apply to my situation). I'll restudy it. Already, I know a lot more.

            Comment


              #21
              Well I'm progressing considerably. I've concluded with this code as order management code to properly exit stops and targets upon stops being hit or targets being hit. Here is my conclusion that seems to replicate performance of SetStopLoss and SetProfitTarget (with conditional orders) (and you are welcome to use or criticize it):

              Code:
              
              if (targetOrder != null && targetOrder.Token == order.Token && order.OrderState == OrderState.Filled && Position.MarketPosition == MarketPosition.Flat)
              { Print(Time[0] + " Cancel stop after target is filled manually in OnOrderUpdate.");
              CancelOrder(stopOrder);
              stopOrder = null;
              targetOrder = null;}
              if (stopOrder != null && stopOrder.Token == order.Token && order.OrderState == OrderState.Filled && Position.MarketPosition == MarketPosition.Flat)
              { Print(Time[0] + " Cancel target Order after STOP is filled manually in OnOrderUpdate.");
              CancelOrder(targetOrder);
              targetOrder = null;
              stopOrder = null;}
              if (stopOrder != null && stopOrder.Token == order.Token && order.OrderState == OrderState.Cancelled)
              stopOrder = null;
              

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by jcbinks, Today, 03:32 PM
              2 responses
              14 views
              0 likes
              Last Post jcbinks
              by jcbinks
               
              Started by Stefan Mayer, Today, 03:09 PM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_Kate  
              Started by M_ichel, Today, 03:18 PM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_ShawnB  
              Started by ralett, Today, 02:43 PM
              2 responses
              15 views
              0 likes
              Last Post ralett
              by ralett
               
              Started by Nightmaregpu, Today, 02:18 PM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X