Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Executed on a Whim

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

    Order Executed on a Whim

    Hello!

    I have an interesting one here.

    I am attaching below the Unmanaged mock strategy which recreates the error for me, here is an explanation of the logic and how it should work:
    1. At 9:29 every day it submits two stoplimit orders above and below price on an oco
    2. Once filled it creates a target and stop OCO
    3. Also creates a 3rd order that is placed at the same spot as the stop called a "Reverse" Order that will execute an entry to the opposite direction
    4. If it hits the Target then it should cancel everything and wait for next entry (Which would be the next day)
    5. If it hits stop then it will obviously fill the other entry order as well and then setup its own stops associated with that entry and stop trading after that trade until next entry (Next day)

    What is happening though is when the Profit Target is hit, it will cancel everything and then randomly go back and re-enter the Reverse order for no reason.
    I put print statements through out, the Reverse Order that is being submitted is hidden behind 2 separate if statements. Neither of those if statements are true when this happens nor do they execute (I have print statements that print as soon as they are true (Just under the if statement). But it will randomly pickout this order submission and submit it again way out of order.

    Lot of stuff here so let me know what else you need from me. Script should be able to recreate. For me happened both directions, obviously the trade needs to hit the profit target in order to execute.

    Thanks!

    File is called ForumTestStrategy
    Attached Files

    #2
    Hello Vikuno1,

    The first possible issue I see in the code are order objects being assigned to variables directly from the order method call return object.

    From the help guide:
    "OnOrderUpdate() will run inside of order methods such as EnterLong() or SubmitOrderUnmanaged(), therefore attempting to assign an order object outside of OnOrderUpdate() may not return as soon as expected. If your strategy is dependent on tracking the order object from the very first update, you should try to match your order objects by the order.Name (signal name) from during the OnOrderUpdate() as the order is first updated."

    The sample code in the help guide demonstrates assigning order objects to variables from OnOrderUpdate().

    Another example using the unmanaged approach can be found here.



    May we have the output saved to a text file showing the issue? (right-click the output window, select Save as)
    Let us know the date and time to look in the output file.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Here is the text of the print statements. Obviously the order of things is in the OnExecution method of the script. As you can see it executes with the execution name "Profit Target" and then randomly jumps to execute the reverse order
      Attached Files

      Comment


        #4
        Hello Vikuno1,

        It looks like multiple actions are occurring.

        I see 'Initial Short 2' likely from the print on line 115, then line 174 is reached, so the position is not long on line 116.
        Then 'Initial Short 4' from line 174, so the execution name 'Initial Short' is not Initial Long.
        With the name 'Initial Short' line 175 is likely evaluating as true.
        There are no prints to show if the conditions on line 183 and 190 are evaluating as true.
        I 'Profit Target 0', 'Profit Target 1', 'Profit Target 6​' so another order may have started filling while this logic is still being evaluated.
        Then I see 'Submitted Reverse Long Initial Short' from the print on line 199 so this lets us know the condition on line 197 was true.

        On line 200 I am seeing an order with the name 'Reverse Long' is being submitted because the condition on lines 197 and 175 was true, and the condition on line 116 was false.

        Then I see 'Initial Short 5', 'Initial Short 6​' from the bottom of which shows this pass of OnExecutionUpdate() has completed.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, 03-13-2026, 05:17 AM
        0 responses
        96 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        154 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        82 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        54 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        72 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X