Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

My stoploss and profit target orders not closed properly

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

    My stoploss and profit target orders not closed properly

    Hi I am placing entry order from onBarUpdate method using EnterLongStopLimit. From the method OnExecutionUpdate , I am placing Stop and Profit target order for the quantity filled using ExitLongStopMarket and ExitLongLimit. The same signal id is being used in all 3 orders. I am obseving couple of issues in live. Kindly help me to resolve this.

    1. when the stop loss order is filled, part of profit target order is not getting closed automatically. when the profit target order is filled, part of stop loss order is not getting closed automatically.
    2. the OnExecutionUpdate is not getting called for all the part filled event and filled event. Due to this, SL/PT order is not placed for all the orders filled.

    onBarUpdate() {
    EnterLongStopLimit(0, true, NoOfContracts, longEntryPrice, longEntryPrice ,"$Long");
    }

    OnExecutionUpdate(){
    longStopOrder = ExitLongStopMarket(0, true, execution.Order.Filled, longSLPrice, "lstop", "$Long");
    longTargetOrder = ExitLongLimit(0, true, execution.Order.Filled, targetPrice, "ltarget", "$Long");
    }​

    #2
    Hello nandhumca,

    The order not being cancelled is expected.

    The opposing order would need to be cancelled with CancelOrder().

    Below is a link to an example 'ProfitChaseStopTrailExitOrdersExample_NT8' with sample code.


    Alternatively, you could use the unmanaged approach and use OCO on these orders. See the 'ProfitChaseStopTrailUnmanagedExample_NT8' example in the same post.


    "2. the OnExecutionUpdate is not getting called for all the part filled event and filled event. "

    This would be unexpected and I am not able to reproduce this behavior on my end.

    Can you print the execution object (without any conditions) in OnExecutionUpdate(), the order object in OnOrderUpdate() to confirm this.
    Provide the output saved to a text file.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank for you reply Chelsea. I have already have Print statement without applying any command. I placed entry order for 10 contracts. The OnExecutionUpdate was called 2 times for 2 part filled contracts. For the rest of the contracts there were not calls.

      I will go thru the sample you have shhared for issue1.

      Comment


        #4
        Hello nandhumca,

        Please provide the output text file so I may assist with analyzing.

        This should have TraceOrders, the order object, and the execution object, and no other prints.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Sure I will enhance the print and share the text file tomorrow.

          Can I use OnOrderUpdate instead of OnExecutionUpdate to place SL/PT order ?

          Comment


            #6
            Hello nandhumca,

            You could use OnOrderUpdate() to submit the exit orders. Note that you will want to check the OrderState of the entry is OrderState.Filled.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              I tried placing ExitLongStopMarket and ExitLongLimit from OnOrderUpdate after checking the state of entry order. But it didn't place the order. no trace on logs and order panel also.

              Comment


                #8
                Hello nandhumca,

                Please provide the output from TraceOrders and Prints.

                Print the order object in OnOrderUpdate().

                What have you written in the condition to detect the order.Name of the entry and the OrderState of the entry?

                Include prints for each value in that condition.

                Below is a link to a forum post that demonstrates using Print() and TraceOrders to understand behavior.


                Attach the output from the output window saved as a text file to your next post and I will be happy to assist in analyzing the output.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Below is the code what i have in order update. I am seeing all below logs on console. But there is no orders in control panel.

                  PrintLogAll("Handling Short Order SL : " + order.Name + " " + orderState + " " + order.Filled);
                  PrintLogAll("Triggering short stop order");
                  shortStopOrder = ExitShortStopMarket(0, true, order.Filled, shortSLPrice, StrategyId+"sstop", @StrategyId+"$Short");
                  PrintLogAll("Triggering long PT order");
                  shortTargetOrder = ExitShortLimit(0, true, order.Filled, targetPrice, StrategyId+"starget", @StrategyId+"$Short");​


                  Below is the log printed on console.

                  Handling Short Order SL : ID1$Short Filled 3
                  Triggering short stop order
                  Triggering long PT order​

                  Comment


                    #10
                    Hello nandhumca,

                    It's best to keep the prints simple so that the output is easy to understand.
                    Be sure you are using Print() to print to the output window only, as demonstrated in the video on using prints.

                    Print the order object in OnOrderUpdate().

                    Print(order.ToString());

                    Make sure that TraceOrders is enabled.

                    Save the output to a text file (right-click the NinjaScript Output window -> select Save As)

                    Note, historical orders are not live real-time orders and will not appear on the Orders tab of the Control Center.

                    This is why we print the order object so we know when historical orders are changing states.



                    Alternatively, you can just start with a working script.

                    Use the ProfitChaseStopTrailExitOrdersExample_NT8 example as your starting point.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    65 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    139 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    75 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    45 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    50 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X