Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limit price can't be smaller than stop price?

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

    Limit price can't be smaller than stop price?

    I've set up a trend strategy using BuyStopLimit which test very well when the Stop is above the Limit, to basically buy as the price rises. It looks like this:

    Code:
    double stopLimitOffsetLong = 0.05;
    orderLong = new OrderRecord
    {
    ThisUUID =ThisUUID,
    LimitPrice = entryPrice+(stopLimitOffsetLong),/// above entry
    StopPrice = entryPrice+(stopLimitOffsetLong*2), /// above entry
    StaticOrderSize = accountEntryQuantity,
    }
    
    
    EnterLongStopLimit(0,true,orderLong.StaticOrderSize,orderLong.LimitPrice,orderLong.StopPrice, orderLong.ThisUUID);
    In the strategy analyzer, this works well. The stop is hit, then it buys.

    In the sim account, I get this:
    Order,Order='39d3c02a54a441a7b8b9767730966eb4/SimAccount1' Name='9efa4' New state='Rejected' Instrument='MES MAR24' Action='Buy' Limit price=5095 Stop price=5096.5 Quantity=1 Type='Stop Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='Order rejected' Native error='Limit price can't be smaller than stop price.',
    3/6/2024 12:05:00 AM,

    Order,SimAccount1 Limit price can't be smaller than stop price. affected Order: Buy 1 StopLimit @ 5096.5 x 5095,

    Why can't this work? It seems like the stop would get hit and then immediate place the limit order because the limit is now less than the buy stop? My goal is the catch the rising price, is there a better way?


    #2
    Hello Skifree,

    Thanks for your post.

    The error message 'Limit price can't be smaller than stop price.', is stating that you are submitting a stop limit order that has the limit price set to a value smaller than the stop price.

    When submitting a stop limit order to enter a long position to an account the limit price must be greater than or equal to the stop price, otherwise the order will be rejected and this error will occur.

    To resolve the error, you will need to modify the logic of your script so that the limit price is greater than or equal to the stop price you are using.

    I suggest adding prints to the script that print out the values you are using for your limit price and stop price to see how those values are evaluating.

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

    <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
      I don't need help with Prints, that's not a helpful suggestion.

      I'm asking why the strategy analyzer doesn't seem to care but simulation does, and if there is a better method for accomplishing this.

      Comment


        #4
        Hello Skifree,

        Thanks for your notes.

        The error is a native error coming from the account you are submitting the order to.

        Order,Order='39d3c02a54a441a7b8b9767730966eb4/SimAccount1' Name='9efa4' New state='Rejected' Instrument='MES MAR24' Action='Buy' Limit price=5095 Stop price=5096.5 Quantity=1 Type='Stop Limit' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='Order rejected' Native error='Limit price can't be smaller than stop price.',

        Depending on the account/brokerage you are running the strategy on, you may see native errors occur specific to that account/brokerage.​

        The Strategy Analyzer does not have a specific account that the is run on when backtesting or optimizing a strategy.

        Ultimately, the EnterLongStopLimit() method requires that you set the Limit Price argument to a value greater than or equal to the value you are using for your Stop Price argument.

        To avoid this error when running the strategy in real-time on an account, you will need to ensure that the Limit Price you are passing into the method is greater or equal to the Stop Price. There would be no available workarounds for this.
        <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, Today, 05:17 AM
        0 responses
        48 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        66 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X