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

Stop-loss and take-profit updating quantity to sum of separate orders

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

    Stop-loss and take-profit updating quantity to sum of separate orders

    Greetings!

    I have an issue where the quantities of my stop-loss and take-profit working orders are being updated to the sum of the individual orders to which they're attached.

    When conditions are right, I create two orders: one scalper and one runner.
    The scalper order has a stop-loss and a take-profit attached to it.
    The runner order only has a parabolic-stop-loss attached to it.

    When both orders are created, the flow of orders seems fine. However, during the call to OnBarUpdate for the next bar, the stop-loss and take-profit working orders have their quantities updated to the sum of the individual scalper and runner orders. This is not good.

    Here are screenshots of relevant code and debug tracing:


    The code in OnStateChange for State == SetDefaults:

    Click image for larger version

Name:	Qaz1.png
Views:	218
Size:	42.1 KB
ID:	1180454



    The code snippet that executes the orders:

    Click image for larger version

Name:	Qaz2.png
Views:	164
Size:	71.8 KB
ID:	1180455


    The trace file contents:

    Click image for larger version

Name:	Qaz3.png
Views:	163
Size:	140.8 KB
ID:	1180457

    I am attaching the trace file (DEBUG.TXT) so that you may have access to the order JSON, which is appended to the end of each order line.

    I would really like to understand why the scalper's stop-loss and take-profit, as well as the runner's parabolic-stop-loss are all having their quantities updated to the sum of the individual order's quantities.

    Thanks.
    Attached Files

    #2
    Hello rgoudie,

    It would be expected that the exit order quantities match the filled quantity for the entry they are attached to.

    What behavior are you expecting?

    Are you expecting the exits quantity to be more than the entry quantities?

    You can use exit orders, like ExitLongStopLimit, and control the quantity of the exit orders if you would like.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi, Chelsea. Thanks for the reply.

      I am not sure why you are referencing exit orders. I never mention exit orders.

      If you view the third image in my initial post, you can see a screenshot of the order flow.
      The green box shows what I expected to happen.
      I set a stop-loss and take-profit for my scalper's signal name, then create an order using that scalper's signal name. The quantity was 4.
      I then set a parabolic stop-loss for the runner's signal name, then created a second order using that runner's signal name. The quantity was 1.

      The green box surrounds what I expect. The orders are created with the correct quantities.

      On the completion of the next bar (2021-08-01 17:40), we see that the quantities of both stop-loss working orders as well as the take-profit working order have all had their quantities updated to the sum of the individual orders: 4 + 1 = 5. I surrounded that section with a red box. This was not expected and breaks my strategy.

      My question remains: why are the quantities being updated in the next bar?


      Originally posted by NinjaTrader_ChelseaB View Post
      Hello rgoudie,

      It would be expected that the exit order quantities match the filled quantity for the entry they are attached to.

      What behavior are you expecting?

      Are you expecting the exits quantity to be more than the entry quantities?

      You can use exit orders, like ExitLongStopLimit, and control the quantity of the exit orders if you would like.

      Comment


        #4
        Hello rgoudie,

        You have stated:
        I have an issue where the quantities of my stop-loss and take-profit working orders are being updated to the sum of the individual orders to which they're attached.
        'stop-loss' and 'take-profit' are terms we use for exits and not for entries. Are you using a stop-loss as an entry order? Are you meaning an entry stop market order with EnterLongStopMarket()?

        Can you clarify how you are not mentioning exits and you are only mentioning entries?

        To answer your question, Set method orders are automatically updated when OnBarUpdate is updated. However, this would refer to exits and not to entries, so I am unsure of what is happening in your script. I would not be expecting the entry order quantities to update, unless you are calling the entry order method again, using the same signal name, with a different quantity. In which case, the logic in the script would be causing the behavior.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by giulyko00, Today, 11:49 AM
        2 responses
        10 views
        0 likes
        Last Post giulyko00  
        Started by Aviram Y, Today, 06:03 AM
        2 responses
        10 views
        0 likes
        Last Post Aviram Y  
        Started by FishTrade, Today, 03:42 PM
        0 responses
        1 view
        0 likes
        Last Post FishTrade  
        Started by Richozzy38, Today, 01:06 PM
        3 responses
        14 views
        0 likes
        Last Post Richozzy38  
        Started by ttrader23, Today, 09:04 AM
        2 responses
        12 views
        0 likes
        Last Post ttrader23  
        Working...
        X