Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

New Strategy - Orders don't get executed

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

    #16
    Hello givemefood,

    Thanks for your note.

    When running the strategy you shared, it placed a Stop Limit order that resulted in an error.

    "Limit price can't be smaller than stop price"

    You would need to ensure that your Stop Limit order Limit price is a value that is greater than the Stop price.

    To determine exactly what values the orders are submitting to, you would need to add debugging prints to the strategy that print out the value being used for the Limit price and Stop price. Then, you could modify the Limit price accordingly so that its greater than the Stop price.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.

    https://ninjatrader.com/support/foru...121#post791121

    See the help guide pages below for more information.
    ExitLongStopLimit: https://ninjatrader.com/support/help...gstoplimit.htm
    ExitShortStopLimit: https://ninjatrader.com/support/help...tstoplimit.htm

    Let me know if I may assist further.​
    Attached Files
    <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


      #17
      thanks, Brandon. Let me try it.

      Comment


        #18
        Brandon,
        It took me a while to get back to relook at the code. I added a print to the code and it produced the following. The issue is only with shorts and not longs. Longs appear to be working fine.

        Here's the code for the short exit orders;
        ExitShortLimit(0, true, Convert.ToInt32(DefaultQuantity), (Position.AveragePrice - (TakeProfit * TickSize)) , @"myProfit", @"myShort");
        ExitShortStopLimit(0, true, Convert.ToInt32(DefaultQuantity), 0, (Position.AveragePrice + (StopLoss * TickSize)) , @"myLoss", @"myShort");

        Here's the printed value appearing on the output window.
        SHORT Position Average Price: 3653 | Exit TP: 3650.75 | Exit SL: 3654.5
        ​
        What's wrong with the code? The values show how it should be placed. They don't seem wrong.
        Any ideas?

        Thanks a bunch.
        Attached Files

        Comment


          #19
          Hello givemefood,

          Thanks for your note.

          Please send me an exported copy of your strategy with the debugging prints included in the strategy and the exact settings/steps used to reproduce the behavior so I may invetigate this further.

          To export a NinjaScript strategy, go to Control Center > Tools > Export > NinjaScript AddOn.

          Exporting: https://ninjatrader.com/support/help...tAsSourceFiles

          I look forward to further assisting.
          <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


            #20
            This was executed/run on a 6 tick range chart on /MES.
            Attached Files

            Comment


              #21
              Hello givemefood,

              Thanks for that information.

              After reviewing and testing the code you shared, I see that this ignored order erroe is a native error message from your broker.

              Some brokers will reject that type of order because you resubmitted a new order at the same price and quantity.

              To avoid this, you would need to make sure to submit your orders to a different price and the order will not be ignored.

              Let me know if I may assist further.

              <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


                #22
                So Brandon, a few follow-up questions. When does this error occur? Is this occurring in Long or short, or both? If it's a native error, what condition can I add to avoid it? Is this related to the error I reported earlier about the ExitShortStopLimit?

                Comment


                  #23
                  I noticed that the main error is on the short entry (not long). It goes back to what I escalated earlier. Attached is the screenshot of the error right after it tries to enter a short order. Error says "Limit price can't be smaller than the stop price". However, for a short, the limit price would be smaller than the stop price. Can you please check the attached log? It has the print towards the end of the log:
                  SHORT Position Average Price: 3628 | Exit TP: 3625.75 | Exit SL: 3629.5
                  Attached Files

                  Comment


                    #24
                    Hello givemefood,

                    Thanks for your note.

                    The error message below is a native error from your broker. This error could be seen in the file you shared on post # 18.

                    9/29/2022 9:23:38 AM Strategy 'MainSimpleStrategyCodeVersion2/275930641': Ignored SubmitOrderManaged() method at 9/29/2022 9:23:38 AM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='myShort' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'

                    Some brokers will reject that type of order because you resubmitted a new order at the same price and quantity. To avoid this, you would need to make sure to submit your orders to a different price and the order will not be ignored. For more information about this limitation, please contact your broker directly.

                    In regard to the error message you shared in post # 23, this indicates that when your Stop Limit order is called, the Limit Price is smaller than the Stop price.

                    To resolve this error, you would need to ensure that the Limit Price argument is larger than your Stop Price argument when calling the Stop Limit order.

                    ExitShortStopLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, double stopPrice, string signalName, string fromEntrySignal)

                    For example, this sample code will cause the same error to be thrown because the Limit Price is smaller than the Stop Price.

                    Code:
                    ExitShortStopLimit(0, true, Position.Quantity, Close[1] + 15*TickSize, Close[1] + 25*TickSize, "MyStop", "MyEntry");
                    The sample code below would be the correct way of calling ExitShortStopLimit(). Note the Limit Price is larger than the Stop Price.

                    Code:
                    ExitShortStopLimit(0, true, Position.Quantity, Close[1] + 35*TickSize, Close[1] + 25*TickSize, "MyStop", "MyEntry");

                    See this help guide page for more information: https://ninjatrader.com/support/help...tstoplimit.htm

                    Ultimately, debugging prints should be added throughout the entire strategy to determine exactly how the strategy is calculating value and submitting orders. Below is a link to a forum post that demonstrates how to use prints to understand behavior.

                    https://ninjatrader.com/support/foru...121#post791121

                    Let me know if I may assist further.
                    Last edited by NinjaTrader_BrandonH; 09-29-2022, 01:27 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

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    66 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    141 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    76 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    47 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    51 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X