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

Executing on near ExitLongLimit

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

    Executing on near ExitLongLimit

    The strategy has 2 ExitLongLimit in OnBarUpdate, one is at SMAFast and the other is at SMAFast2. Once the strategy has a position (entering 2 lots at a time), it will place a 2 limit orders, one at each price to exitLongLimit.

    I'm referencing OnExecutionUpdate the entry orders to place the two initial exits once filled, and I am using ChangeOrder in OnBarUpdate() to call change to the two exits which have different order object names.

    The problem is that once the SMAFast is reached, it will sell 1, but it will also sell the other. I am guessing that on the next onbarupdate, it just reloads the SMAFast order again to exitlonglimit. But I don't want that. Once that order is filled, that order should be dead.

    Any ideas?

    #2
    Hello Boonfly8,

    Thanks for your post.

    Without the code and taking debugging steps I could only speculate on the issue you are encountering.

    If you are using Order objects, you should be following as a best practice:
    1. Assigning Order objects in OnOrderUpdate() (not necessary as order objects can be assigned directly from the order methods, but best practice)
    2. Transitioning Order objects in State.Realtime with GetRealtimeOrder()
    3. Setting the Order object to null in OnExecution if the order is filled, and also in OnOrderUpdate() if the order is cancelled


    More information on using Order Objects can be referenced in the documentation below and the SampleOnOrderUpdate strategy can be referenced as a working example.

    Advanced Order Handling - https://ninjatrader.com/support/help...r_handling.htm

    SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

    In addition to noting these practices, I would then suggest to take debugging steps to determine exactly why the exit method is getting called again. Adding prints that tell you about the conditions that control your order submission logic outside of that condition will tell you how that condition gets evaluated and will show how it needs to be corrected.

    For example:

    Print("CondA: " + CondA + " CondB: " + CondB);
    if (CondA && CondB)
    ExitLong();

    will tell you about the conditions that control the exit and why that exit has become true.

    Debugging Tips that can be used to further study your code execution can be referenced below.

    Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

    TraceOrders - https://ninjatrader.com/support/help...aceorders2.htm

    Please let us know if there is anything else we can do to help.
    JimNinjaTrader Customer Service

    Comment


      #3
      Could this be a limitation of NT8? I am using 1 signal name "LONG" and I am trying to exit half the position at a certain price and the other half at another. With some research in past forum posts, people have suggested scaling in with different entry names...

      Comment


        #4
        Hello Boonfly8,

        That is a good theory and may be the case if you are submitting multiple exits with the same exit signal name. This isn't exactly a limitation of NinjaTrader but a logical limitation. If we we are exiting a position in two instances, we will be submitting 2 orders to flatten the position. We should then use 2 Order objects for each Exit Signal Name.

        The attached strategy may not reflect what you are trying to do verbatim, but should be enough to demonstrate entering a position, and exiting under 2 separate events.

        If you have any additional questions surrounding this matter, please let us know.
        Attached Files
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by alifarahani, Today, 09:40 AM
        6 responses
        36 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Kaledus, Today, 01:29 PM
        5 responses
        14 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Waxavi, Today, 02:00 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by gentlebenthebear, Today, 01:30 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X