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

Unmanaged Order State And OnExecution event

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

    Unmanaged Order State And OnExecution event

    I have 3 questions.
    1. I am painfully working on a system that uses unmanaged orders. With a every a position, a stop must be placed. Originally I used the OnPositionUpdate event to make sure my stop and limit order was placed on every new position. It did strange things like cancelling the orders rather than placing them. Finally I tried handling fills in the OnExecution (and got rid of the OnPositionUpdate event handler completely) event handler and checked that a new position resulted from the execution and now it works. I am curious as why this might be as my flawed intuition says to use the OnPositionUpdate event handler would make the most sense.

    2. If an order object's order state is filled and a CancelOrder function is being called, what happens internally? What happens when the SubmitOrder function is called on an order object whose order state is filled?

    3. Is there a way to ensure a stop is placed on every position outside of the program in Ninja Trader itself such as a setting?

    Knowing this might help me to debug some minor issues that are still occurring in real time.

    Thank you,

    Cowpux

    #2
    Hello Cowpux,

    Thanks for your post.

    1. It is preferred to set protective orders in OnExecution as this will relate to the order specifically and will trigger these at the time the order fills.

    You would need fancy logic within OnPositionUpdate that checks the current IOrder objects to see what is filling and when. This can introduce issues as it is not guaranteed that OnExecution or OnOrderUpdate will have run yet and updated the IOrder object.

    Basically if you want to place protective orders do this in OnExecution.

    If you want to do calculations and things that are specific to the position like the avg position amount etc. this would be fine to do in OnPositionUpdate. OnPositionUpdate is a good place to gather information.


    2. An overfill occurs.

    From the help guide:
    "An overfill is categorized as when an order returns a "Filled" or "PartFilled" state after the order was already marked for cancellation. The cancel request could have been induced by an explicit CancelOrder() call, from more implicit cancellations like those that occur when another order sharing the same OCO ID is filled, or from things like order expirations."
    http://www.ninjatrader.com/support/h...reoverfill.htm

    Always check that an order is not in the OrderState.Filled state before attempting to cancel an order.

    If an order is submitted and there is already a filled order, then a new order is submitted as long as the entries per direction allows for an additional order.

    If the order is still working and the same signal name is used and the price is different the working order is matched and modified.

    3. It would take a lot of work and a lot of unsupported code, but theoretically yes, it would be possible to make some script that monitors your account and places protective orders for any order placed manual or from a strategy. This would need to be very sophisticated as it would have total control over all of your ordering.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by algospoke, 04-17-2024, 06:40 PM
    6 responses
    49 views
    0 likes
    Last Post algospoke  
    Started by arvidvanstaey, Today, 02:19 PM
    4 responses
    11 views
    0 likes
    Last Post arvidvanstaey  
    Started by samish18, 04-17-2024, 08:57 AM
    16 responses
    61 views
    0 likes
    Last Post samish18  
    Started by jordanq2, Today, 03:10 PM
    2 responses
    9 views
    0 likes
    Last Post jordanq2  
    Started by traderqz, Today, 12:06 AM
    10 responses
    21 views
    0 likes
    Last Post traderqz  
    Working...
    X