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

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.

    Brandon H.NinjaTrader Customer Service

    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.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by halgo_boulder, 04-20-2024, 08:44 AM
        2 responses
        21 views
        0 likes
        Last Post halgo_boulder  
        Started by mishhh, 05-25-2010, 08:54 AM
        19 responses
        6,189 views
        0 likes
        Last Post rene69851  
        Started by gwenael, Today, 09:29 AM
        0 responses
        5 views
        0 likes
        Last Post gwenael
        by gwenael
         
        Started by Karado58, 11-26-2012, 02:57 PM
        8 responses
        14,830 views
        0 likes
        Last Post Option Whisperer  
        Started by Option Whisperer, Today, 09:05 AM
        0 responses
        2 views
        0 likes
        Last Post Option Whisperer  
        Working...
        X