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

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:
              [FONT=Courier New][SIZE=2]
              [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (targetOrder != [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] && targetOrder.Token == order.Token && order.OrderState == OrderState.Filled && Position.MarketPosition == MarketPosition.Flat)
              { Print(Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] + [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]" Cancel stop after target is filled manually in OnOrderUpdate."[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
              CancelOrder(stopOrder);
              stopOrder = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];
              targetOrder = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];}
              [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (stopOrder != [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] && stopOrder.Token == order.Token && order.OrderState == OrderState.Filled && Position.MarketPosition == MarketPosition.Flat)
              { Print(Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] + [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]" Cancel target Order after STOP is filled manually in OnOrderUpdate."[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);
              CancelOrder(targetOrder);
              targetOrder = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];
              stopOrder = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];}
              [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (stopOrder != [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] && stopOrder.Token == order.Token && order.OrderState == OrderState.Cancelled)
              stopOrder = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]null[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];
              [/SIZE][/FONT]

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by TheMarlin801, 10-13-2020, 01:40 AM
              20 responses
              3,914 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by timmbbo, 07-05-2023, 10:21 PM
              3 responses
              151 views
              0 likes
              Last Post grayfrog  
              Started by Lumbeezl, 01-11-2022, 06:50 PM
              30 responses
              807 views
              1 like
              Last Post grayfrog  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              3 responses
              11 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by Johnny Santiago, 10-11-2019, 09:21 AM
              95 responses
              6,194 views
              0 likes
              Last Post xiinteractive  
              Working...
              X