Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

An Enter() method to submit an entry order has been ignored

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

    An Enter() method to submit an entry order has been ignored

    I am developing a custom strategy and I often get messages like the one below in the Output window. This occurs often when I am back testing using Strategy Analyzer. I am unsure why this warning message appears. I understand the warning is referring to this section of the docs.

    Strategy 'MyCustomStrategy/-1': An Enter() method to submit an entry order at '9/8/2023 10:59:16 AM' has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.
    I my strategy, I use the Managed Approach. I only take 1 trade at time and another trade is not taken until I am flat. Therefore, I am not sure why I am getting this warning message. Below is my general pseudo code for my strategy.

    Code:
    protected override void OnBarUpdate()
    {
    
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    
    bool place_order = SomeCustomMethod();
    
    // Other code to determine entry price, profit price, stop price goes here
    
    if (place_order)
    {
    
    SetProfitTarget(mode: CalculationMode.Price, value: my_profit_price, fromEntrySignal: my_label);
    SetStopLoss(mode: CalculationMode.Price, value: my_stop_price, fromEntrySignal: my_label, isSimulatedStop: false);
    
    if (trade_direction)
    entryOrder = EnterLongLimit(limitPrice: my_entry_price, signalName: my_label, quantity: 1);
    else
    entryOrder = EnterShortLimit(limitPrice: my_entry_price, signalName: my_label, quantity: 1);
    
    }
    
    }

    #2
    Hello wzgy0920,

    Thanks for your post.

    From the Managed Approach help guide page:

    Methods that generate orders to enter a position will be ignored if:
    • A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
    • A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction
    • A position is open and two or more Entry methods to reverse the position are entered together. In this case the second Entry order will be ignored.
    • The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
    • The entry signal name is not unique
    It seems that you are using the same signal name for each of the Enter order methods in your script. Each Enter order method should have a unique signal name.

    You should also review the scenarios listed above and compare them to your script to ensure that the strategy is not falling into a different scenario other than 'The entry signal name is not unique'.

    Managed Approach Internal Order Handling Rules: https://ninjatrader.com/support/help...d_approach.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello wzgy0920,

      It seems that you are using the same signal name for each of the Enter order methods in your script. Each Enter order method should have a unique signal name.

      You should also review the scenarios listed above and compare them to your script to ensure that the strategy is not falling into a different scenario other than 'The entry signal name is not unique'.

      Managed Approach Internal Order Handling Rules: https://ninjatrader.com/support/help...d_approach.htm
      In my code, my signal name is a unique string that uniquely describes the entry location and relevant info of my calculation. If the trade is filled then only the exit orders (i.e. stop/profit order) would have that same signal name. A new trade with the same signal name cannot be taken if I already a position open. This is because I only do EnterLongLimit/EnterShortLimit if Position.MarketPosition == MarketPosition.Flat. Therefore, I am unsure what I am doing wrong.

      Comment


        #4
        Hello wzgy0920,

        Thanks for your notes.

        Without seeing the entirety of the script I would not be able to say for certain what exactly in your code is against the Managed Approach Internal Order Handling Rules linked on post # 2.

        If you would like to share a copy of the strategy with me then I would be happy to take a look at the code to see if anything stands out.

        Otherwise, you would need to make sure that your strategy is not submitting an order to open a position in the opposite direction in an open position and a non market exit order, such as ExitLongLimit(), is active.

        You should also make sure that two or more Entry methods to reverse the position are entered/submitted together.

        Also, ensure that you are not using Set Methods, such as SetStopLoss, and non-market Exit Methods, such as ExitLongLimit(), within the same NinjaScript strategy. Only Set methods OR Exit methods could be used in the same script, not both.

        Ensure that if the strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active you are not submitting an order used to open a position in the opposite direction

        And, add prints to the script that print out the Signal Name of the Entry orders to ensure the Signal Names are unique.

        See the Internal Order Handling Rules section on this help guide page: https://ninjatrader.com/support/help...ach.htm​
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          I'll go through my code again and try to debug further. Is it possible I can email you the sample script if I am unable to figure it out? I have some additional questions below which may help me debug further.

          1) Is it possible to catch when Ninjatrader emits the warning "Strategy 'MyCustomStrategy/-1': An Enter() method to submit an entry order..."? I would like to gather additional info such as CurrentBar, time, etc so I can try to replicate this issue.

          2) In my pseudo code shared above, I submit the SetProfitTarget/SetStopLoss before submitting the EnterLongLimit/EnterShortLimit. Is this a valid approach as long as the signal name is the same? Should I put the SetProfitTarget/SetStopLoss inside OnOrderUpdate or OnExecutionUpdate method instead?

          Comment


            #6
            Hello wzgy0920,

            Thanks for your notes.

            Yes, you could email a simple reduced script that demonstrates the error to support[at]ninjatrader[dot]com so that we may look at the simple script and see if anything specific stands out in the code. In the Subject of the email include 'Attn: BrandonH' and in the Body of the email include a link to this forum thread.

            Note that a reduced copy refers to a copy of the script that contains the minimum amount of code needed to reproduce the issue. All other code is commented out or removed.

            To create a copy of your script to modify, open a New > NinjaScript Editor, select your script, right-click in the Editor, select 'Save as', name the script, and click OK.

            The Playback connection could be used with Market Replay data to try and replicate the behavior and debug the script.

            Playback: https://ninjatrader.com/support/help...8/playback.htm

            1: You could consider adding prints to your script one line above where the Enter order method is called that prints out the CurrentBar and the Time[0]. You could also enable TraceOrders to get further information about the behavior of orders.

            TraceOrders: ​https://ninjatrader.com/support/help...sub=traceorder

            Below is a link to a forum post that demonstrates how to use prints to understand behavior.
            https://ninjatrader.com/support/foru...121#post791121

            2. Set methods should be called prior to submitting entry orders since Set methods prep NinjaTrader to submit protective orders as noted on the SetStopLoss() and SetProfitTarget() help guide documentation.

            SetStopLoss(): https://ninjatrader.com/support/help...etstoploss.htm
            SetProfitTarget(): https://ninjatrader.com/support/help...ofittarget.htm

            That said, in your case, you might be best off ​using Exit methods, such as ExitLongLimit() and ExitLongStopMarket(), for your protective orders instead of Set methods. You could create a condition that checks if you are in a Long market position (Position.MarketPosition == MarketPosition.Long) or Short market position (Position.MarketPosition == MarketPosition.Short) and then call your Exit methods to place the stop and target orders once the order is filled.

            Position.MarketPosition: https://ninjatrader.com/support/help...etposition.htm
            ExitLongLimit(): https://ninjatrader.com/support/help...tlonglimit.htm
            ExitLongStopMarket(): https://ninjatrader.com/support/help...stopmarket.htm
            ExitShortLimit(): https://ninjatrader.com/support/help...shortlimit.htm
            ExitShortStopMarket(): https://ninjatrader.com/support/help...stopmarket.htm
            Last edited by NinjaTrader_BrandonH; 09-21-2023, 01:35 PM.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7
              Brandon, thank you for the insights. I will continue to troubleshoot. When running on strategy on a real account live, I often the error show in the screenshot below. Is this related? What is causing the error below? How can I troubleshoot it?

              Click image for larger version

Name:	image.png
Views:	781
Size:	111.1 KB
ID:	1269998

              Comment


                #8
                Hello wzgy0920,

                This error is stating you have used an invalid price for the stop order.

                Buy stop orders must be above the ask, sell stop orders must be below the bid.
                Hi I have a sellshort StopLimit order that i change if unfilled. I tick below the last bar's low. I keep getting the stop price can't be changed above the market but the price value it quotes ( the one I want) is below the market. Currently I am on the simulated feed. I appreciate in real market situations this could happen
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I ran the my strategy in playback with TraceOrders enabled. Below is output from one of the instances where I get warning. I still don't understand why I am getting the warning. Based on the output for the TraceOrders, I had a pending buy limit order at LimitPrice=4486.00 which was never filled. Then my signal changed, so my strategy submitted a sell limit order at LimitPrice=4489.75. However, this resulted in the warning message. Later, the new sell limit order was submitted properly.


                  Code:
                  9/19/2023 10:10:01 PM Strategy 'MyCustomStrategy/300201326': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='PA02FT4 L=0.6 S=0.1' Mode=Price Value=4492 IsSimulatedStop=False IsMarketIfTouched=False
                  9/19/2023 10:10:01 PM Strategy 'MyCustomStrategy/300201326': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='PA02FT4 L=0.6 S=0.1' Mode=Price Value=4477.5 IsSimulatedStop=False IsMarketIfTouched=False
                  9/19/2023 10:10:01 PM Strategy 'MyCustomStrategy/300201326': Entered internal SubmitOrderManaged() method at 9/19/2023 10:10:01 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=4486.00 StopPrice=0 SignalName='PA02FT4 L=0.6 S=0.1' FromEntrySignal=''
                  9/19/2023 10:10:01 PM Strategy 'MyCustomStrategy/300201326': Ignored SubmitOrderManaged() method at 9/19/2023 10:10:01 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=4486.00 StopPrice=0 SignalName='PA02FT4 L=0.6 S=0.1' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'
                  9/19/2023 10:10:03 PM Strategy 'MyCustomStrategy/300201326': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='CZO5WFN L=0.3 S=0.6' Mode=Price Value=4488.5 IsSimulatedStop=False IsMarketIfTouched=False
                  9/19/2023 10:10:03 PM Strategy 'MyCustomStrategy/300201326': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='CZO5WFN L=0.3 S=0.6' Mode=Price Value=4491.75 IsSimulatedStop=False IsMarketIfTouched=False
                  9/19/2023 10:10:03 PM Strategy 'MyCustomStrategy/300201326': Entered internal SubmitOrderManaged() method at 9/19/2023 10:10:03 PM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=4489.75 StopPrice=0 SignalName='CZO5WFN L=0.3 S=0.6' FromEntrySignal=''
                  9/19/2023 10:10:03 PM Strategy 'MyCustomStrategy/300201326': Ignored SubmitOrderManaged() method at 9/19/2023 10:10:03 PM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=4489.75 StopPrice=0 SignalName='CZO5WFN L=0.3 S=0.6' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.'
                  Strategy 'MyCustomStrategy/300201326': An Enter() method to submit an entry order at '9/19/2023 10:10:02 PM' has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.
                  9/19/2023 10:10:03 PM Strategy 'MyCustomStrategy/300201326': Cancelled expired order: BarsInProgress=0, orderId='fe83276d12d54bc0af9d757b77c6ce8b' account='Playback101' name='PA02FT4 L=0.6 S=0.1' orderState=Working instrument='ES 12-23' orderAction=Buy orderType='Limit' limitPrice=4486 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=10956 time='2023-09-19 21:43:18' gtd='2099-12-01' statementDate='2023-09-19'
                  9/19/2023 10:10:07 PM Strategy 'MyCustomStrategy/300201326': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='CZO5WFN L=0.3 S=0.6' Mode=Price Value=4488.5 IsSimulatedStop=False IsMarketIfTouched=False
                  9/19/2023 10:10:07 PM Strategy 'MyCustomStrategy/300201326': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='CZO5WFN L=0.3 S=0.6' Mode=Price Value=4491.75 IsSimulatedStop=False IsMarketIfTouched=False
                  9/19/2023 10:10:07 PM Strategy 'MyCustomStrategy/300201326': Entered internal SubmitOrderManaged() method at 9/19/2023 10:10:07 PM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=4489.75 StopPrice=0 SignalName='CZO5WFN L=0.3 S=0.6' FromEntrySignal=''

                  Comment


                    #10
                    Hello wzgy0920,

                    Thanks for your notes.

                    "9/19/2023 10:10:01 PM Strategy 'MyCustomStrategy/300201326': Ignored SubmitOrderManaged() method at 9/19/2023 10:10:01 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=4486.00 StopPrice=0 SignalName='PA02FT4 L=0.6 S=0.1' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'"

                    This error message indicates that the order was ignored because you already have a matching order with the same prices and quantity.

                    If you are trying to scale into or out of a strategy, scaling into a position is controlled with the signal names of your strategy, and properties EntryHandling and EntriesPerDirection. This reference sample can help with scaling in and out of a strategy.
                    https://ninjatrader.com/suppport/helpGuides/nt8/en-us/scaling_out_of_a_position.htm

                    This sample can assist further with managing multiple exit/entry signals:
                    https://ninjatrader.com/support/helpGuides/nt8/en-us/using_multiple_entry_exit_sign.htm


                    "9/19/2023 10:10:03 PM Strategy 'MyCustomStrategy/300201326': Ignored SubmitOrderManaged() method at 9/19/2023 10:10:03 PM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=4489.75 StopPrice=0 SignalName='CZO5WFN L=0.3 S=0.6' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.'"

                    This error message indicated that an order was ignored to enter a position because a Managed Approach Internal Order Handling Rule was broken.

                    As noted in post # 2: Methods that generate orders to enter a position will be ignored if:
                    • A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
                    • A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction
                    • A position is open and two or more Entry methods to reverse the position are entered together. In this case the second Entry order will be ignored.
                    • The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
                    • The entry signal name is not unique
                    Please review this help guide documentation about the Managed Approach Internal Order Handling Rules and compare the rules to your code to ensure you are not breaking any of the internal order handling rules.
                    https://ninjatrader.com/support/help...d_approach.htm

                    Also, see post # 4 on this forum thread for more information.
                    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                    Comment


                      #11
                      Originally posted by NinjaTrader_BrandonH View Post

                      "9/19/2023 10:10:01 PM Strategy 'MyCustomStrategy/300201326': Ignored SubmitOrderManaged() method at 9/19/2023 10:10:01 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=4486.00 StopPrice=0 SignalName='PA02FT4 L=0.6 S=0.1' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'"

                      This error message indicates that the order was ignored because you already have a matching order with the same prices and quantity.

                      If you are trying to scale into or out of a strategy, scaling into a position is controlled with the signal names of your strategy, and properties EntryHandling and EntriesPerDirection. This reference sample can help with scaling in and out of a strategy.
                      https://ninjatrader.com/suppport/helpGuides/nt8/en-us/scaling_out_of_a_position.htm
                      I am not scaling in/out of a position. I think this errors occurs because I keep re-submitting the same order until it is filled or until that specific trade signal is no longer valid. The documentation says: By default, orders are kept alive, provided they are re-submitted on each call of the OnBarUpdate() method. If an order is not re-submitted, it is then canceled. The pseudo code I shared in my original post Home does just this... How else am I suppose to submit the order?


                      Originally posted by NinjaTrader_BrandonH View Post

                      "9/19/2023 10:10:03 PM Strategy 'MyCustomStrategy/300201326': Ignored SubmitOrderManaged() method at 9/19/2023 10:10:03 PM: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=4489.75 StopPrice=0 SignalName='CZO5WFN L=0.3 S=0.6' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.'"

                      This error message indicated that an order was ignored to enter a position because a Managed Approach Internal Order Handling Rule was broken.

                      As noted in post # 2: Methods that generate orders to enter a position will be ignored if:
                      A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
                      A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction
                      A position is open and two or more Entry methods to reverse the position are entered together. In this case the second Entry order will be ignored.
                      The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction
                      The entry signal name is not unique
                      Please review this help guide documentation about the Managed Approach Internal Order Handling Rules and compare the rules to your code to ensure you are not breaking any of the internal order handling rules.
                      https://ninjatrader.com/support/help...d_approach.htm

                      Also, see post # 4 on this forum thread for more information.
                      Well this is the main issue I am trying to figure out why it is happening. As shown in the TraceOrders output, I do NOT have any open positions. My previous buy order LimitPrice=4486.00​ never got filled. Now the signal changed to short direction, so I submit a new order which is sell with LimitPrice=4489.75.Why am I getting the error if I am already flat and there are no open positions!

                      Comment


                        #12
                        Hello wzgy0920,

                        Thanks for your notes.

                        To keep the Enter methods alive instead of the order being canceled at the end of a bar or having to be re-submitted you could use the isLiveUntilCancelled overload for the Enter methods.

                        The isLiveUntilCancelled property could be set to true to keep the orders alive and ensure that your logic is only calling the Enter methods once so that the order does not reset. When the isLiveUntilCancelled property is set to true the order will NOT expire at the end of a bar but instead remain live until the CancelOrder() method is called or its time in force is reached.

                        EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)
                        EnterShortLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)


                        EnterLongLimit(): https://ninjatrader.com/support/help...rlonglimit.htm
                        ​EnterShortLimit(): https://ninjatrader.com/support/help...shortlimit.htm

                        The Internal Order Handling Rules below could possibly cause the ignored order when in a flat position.

                        The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction

                        This means you cannot be in a flat position and have an EnterLongLimit() order active (working) and then submit an order to open a position in the opposite direction.

                        The entry signal name is not unique

                        Ensure that each signal name for the orders you are submitting is unique. One line above your Enter method, print out the signal name you are assigning to the order method.​

                        To clarify, are you using Exit methods and Set methods within your strategy?

                        Without seeing the entirety of the script I would not be able to say for certain what exactly in your code is against the Managed Approach Internal Order Handling Rules.

                        If you would like to share a copy of the strategy with me then I would be happy to take a look at the code to see if anything stands out.
                        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                        Comment


                          #13
                          Originally posted by NinjaTrader_BrandonH View Post

                          The Internal Order Handling Rules below could possibly cause the ignored order when in a flat position.

                          The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction

                          This means you cannot be in a flat position and have an EnterLongLimit() order active (working) and then submit an order to open a position in the opposite direction.
                          This was the helpful. I changed my code to use isLiveUntilCancelled. My initial test show that the warning, An Enter() method to submit an entry order..., doesn't appear anymore. I will need to do some additional testing to confirm the issue is resolved. Can you please look at my pseudo code below to confirm if I am using best practice to keep track of the existing order and canceling it when I get a new trade signal? One issue I am having with this approach is the if I cancel an order manually from the chart, then new orders are not being placed even though the strategy is running properly and it is detecting a new trade signal.

                          Code:
                          protected override void OnBarUpdate()
                          {
                          if (Position.MarketPosition == MarketPosition.Flat)
                          {
                          
                          bool place_order = SomeCustomMethod();
                          
                          // Other code to determine entry price, profit price, stop price goes here
                          
                          if (place_order)
                          {
                          
                          if (current_setup_label != my_label && myEntryOrder != null)
                          {
                          CancelOrder(myEntryOrder);
                          }
                          
                          if (myEntryOrder == null)
                          {
                          current_setup_label = my_label;
                          
                          SetProfitTarget(mode: CalculationMode.Price, value: my_profit_price, fromEntrySignal: my_label);
                          SetStopLoss(mode: CalculationMode.Price, value: my_stop_price, fromEntrySignal: my_label, isSimulatedStop: false);
                          
                          if (setup_direction)
                          EnterLongLimit(limitPrice: my_entry_price, signalName: setup_label_hash, quantity: 1, isLiveUntilCancelled: true, barsInProgressIndex: 0);
                          else
                          EnterShortLimit(limitPrice: my_entry_price, signalName: setup_label_hash, quantity: 1, isLiveUntilCancelled: true, barsInProgressIndex: 0);
                          }
                          
                          
                          }
                          else
                          {
                          CancelOrder(myEntryOrder);
                          }
                          }
                          
                          
                          protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
                          {
                          if (myEntryOrder == null && order.Name == current_setup_label)
                          {
                          myEntryOrder = order;
                          }
                          
                          if (myEntryOrder != null && order.Name == current_setup_label)
                          {
                          if (order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Rejected || order.OrderState == OrderState.Filled)
                          {
                          myEntryOrder = null;
                          }
                          
                          }
                          }

                          Comment


                            #14
                            Hello wzgy0920,

                            Thanks for your notes.

                            When using CancelOrder(), the entry order should be tracked in OnOrderUpdate() as seen in the code you shared. I do not see anything specific in the code you shared that is standing out.

                            That said, should call the SetStopLoss() and SetProfitTarget() method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position. This is noted on the SetStopLoss() and SetProfitTarget() help guide documentation.​

                            Here is a reference sample you could view demonstrating the use of CancelOrder() in a strategy: https://ninjatrader.com/support/help...thod_to_ca.htm

                            See this help guide page for more information about CancelOrder(): https://ninjatrader.com/support/help...ancelorder.htm

                            Here is a reference sample demonstrating dynamically calling Set methods in OnBarUpdate(): https://ninjatrader.com/support/help...of_stop_lo.htm

                            SetStopLoss(): https://ninjatrader.com/support/help...etstoploss.htm
                            SetProfitTarget: https://ninjatrader.com/support/help...ofittarget.htm

                            If the script is not behaving as expected then you should use debugging prints to understand exactly how your logic is evaluating.

                            Below is a link to a forum post that demonstrates how to use prints to understand behavior.
                            https://ninjatrader.com/support/foru...121#post791121
                            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                            Comment


                              #15
                              Originally posted by NinjaTrader_BrandonH View Post

                              When using CancelOrder(), the entry order should be tracked in OnOrderUpdate() as seen in the code you shared. I do not see anything specific in the code you shared that is standing out.

                              That said, should call the SetStopLoss() and SetProfitTarget() method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position. This is noted on the SetStopLoss() and SetProfitTarget() help guide documentation.​
                              In live realtime trading, I now sometimes gets errors like the one in screenshot below. In my Output window, I don't see any other errors related to this. Not sure why this is happening and how to avoid it.

                              Click image for larger version  Name:	image.png Views:	0 Size:	21.7 KB ID:	1270569

                              Regarding your comment about ​resetting the SetStopLoss/SetProfitTarget. I'll do as you suggested. However, I don't understand why I have to reset them when I am flat. Based on my pseudo code, you can see I submit the SetStopLoss/SetProfitTarget orders before the EnterLongLimit/EnterShortLimit orders. Therefore there can't be a situation where the previous Stop/Loss values would be used when my next position is opened. Unless I am not understanding or missing some other considerations.
                              Last edited by wzgy0920; 09-27-2023, 10:10 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              52 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              130 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              70 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              43 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              47 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X