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 franjcy, 06-15-2024, 01:23 PM
    8 responses
    43 views
    0 likes
    Last Post franjcy
    by franjcy
     
    Started by samish18, Today, 10:13 AM
    0 responses
    5 views
    0 likes
    Last Post samish18  
    Started by AlphaTonicCA, Today, 09:53 AM
    0 responses
    5 views
    0 likes
    Last Post AlphaTonicCA  
    Started by Skatester, Today, 09:22 AM
    0 responses
    7 views
    0 likes
    Last Post Skatester  
    Started by ms52390, 06-20-2024, 03:48 PM
    2 responses
    16 views
    0 likes
    Last Post ms52390
    by ms52390
     
    Working...
    X