Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATM strategy StopLimit orders rejected

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

    ATM strategy StopLimit orders rejected

    I have a strategy that executes as expected using Backtest and Optimizer, but won’t run in Replay mode or in Sim mode w live data feed. I’m not sure why it runs in Backtest but not in Replay, Sim, or on actual live data.

    Basically what I’m trying to do is: If the current price goes above the previous bar’s high, then I want to want to place a buyLmt order at the previous bars High -5 Ticks; a buy a breakout on retracement strategy.

    If someone can point out why the code below isn’t working, what I need to change or an alternative method of doing this I’d really appreciate it!

    My code, error messages, & logs are below:


    #region Variables
    // Wizard generated variables
    privateint lLmtTs = -5; // Default setting for LLmtTs

    If conditions x y & z are met:
    {
    EnterLongStopLimit(DefaultQuantity, High[0] + LLmtTs * TickSize, High[0] + 1 * TickSize, "Enter Long on lmt ");
    }

    In Replay when the conditions are met I immediately get the following messages:

    1) Strategy submitted an order that generated the following error ‘OrderRejected’. Strategy has sent cancel requests, attemted to close the position and terminated itself.

    2) Limit price can’t be smaller than stop price. Affected Order: Buy 1 StopLimit @ 1215.5 x 1214

    The log leading up to is as follows:

    -3/21/2009 8:45:18 PM Default Simulation account 'Replay101' reset


    -3/21/2009 8:45:22 PM Strategy Starting NinjaScript strategy 'RHK101fb/6c2a19cf42ee4b7197de2cd8fe4c1df0' : On starting a real-time strategy - StrategySync=SubmitLive EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 60 before close Set order quantity by=Strategy


    -3/21/2009 8:45:46 PM Order Order='231fc130099a4622b831286ea0913a1e/Replay101' Name='Enter Long on lmt ' New State=Rejected Instrument='NQ 06-09' Action=Buy Limit price=1214 Stop price=1215.5 Quantity=1 Type=StopLimit Filled=0 Fill price=0 Error=OrderRejected Native error='Limit price can't be smaller than stop price.'


    -3/21/2009 8:45:46 PM Order Limit price can't be smaller than stop price. Affected Order: Buy 1 StopLimit @ 1215.5 x 1214
    -3/21/2009 8:45:46 PM Strategy Strategy 'RHK101fb' submitted an order that generated the following error 'OrderRejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself.

    #2
    Hello,

    The limit price must be larger than the stop price. Try switching your stop and limit prices.

    This link may help:
    DenNinjaTrader Customer Service

    Comment


      #3
      Hi Ben Thanks for the reply,

      I tried reversing the stop & lmt prices as you suggested but still get the same error messages; although this would no longer do what I was trying to do.

      I’m trying to duplicate what I do in my actual trading in chart trader where I put a Buystop above the previous bar’s H with a negative limit amount of -5 ticks. I believe a simulated order that is designated in yellow on Chart trader.

      Do you (or anyone else) have any suggestions how to code this in ninja script or could point me to a link on how to code how to this – basically buying after breakout on a retracement?

      Or did your previous answer, “The limit price must be larger than the stop price.” Mean this can’t be done in ninja script, and can only be done in Chart trader?

      It’s interesting that the code originally present that runs in the optimizer & backtest modes, but then won’t run in live trading, or replay.

      Obviously, I’ve just starting on trying to learn how to code in Ninja Script, so any suggestions accomplished the above are welcomed.
      Sorry for the slow reply, I was trying (unsuccessfully) to code the above in a different way.

      Comment


        #4
        robhef,

        Please describe exactly which orders you are trying to send and in which direction. Thank you.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          When several conditions are met, I’m trying to use the following order to get long after the previous bar’s High has been exceeded by 1 Tick (trigger), after which point I want to place a Buylimit order at the previous bar’s High – 5 Ticks. To do this I’ve tried use the following order:

          EnterLongStopLimit(DefaultQuantity, High[1] - 5 * TickSize, High[0] + 1 * TickSize, "Enter Long on lmt "

          But when I run the strategy I get an error message “The limit price can’t be smaller than the stop price and the strategy is closed and orders cancelled.

          I have just completely commented out the short entry side, which I figure I can get to work if I can get the long side to enter at the correct limit price.

          I’ve also tried the following code: If High[0] > High[1] Then
          EnterLongLimit(DefaultQuantity, High[1] - 5 * TickSize, ""

          The above order does not cause the strategy to get canceled, but it gets filled ONLY 1 Tick below H[1] instead of 5Ticks below H[1].

          Its probably something simple I’m not doing, but I can’t see it. Thanks for you help. Rob.

          Comment


            #6
            robhef,

            You have swapped the parameters around. It is limit price first then stop price.

            Your limit price is High[1] + TickSize.
            Your stop price is High[1] - 5 * TickSize.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh, it looks like I have swapped them, but I want to buy at a -5 Tick retracment limitprice after the trigger price of H[1] +Tick has been penetrated during the current bar.

              I'm trying to duplicate what I can do in Chart trader, where I put a simulated stop limit order with the stop at 1 Tick above the previous bar's High that has a buylimit value of H[1] - 5Ticks. That order rests 1 Tick above H[1] while C[0] is <= High[1]. But if the Close[0] price breaks out above the H[1], then a buylimit order at H[1] -5 Ticks is placed in the market and would get executed if the price pulls back to H[1] - 5Ticks.

              Comment


                #8
                That is the exact condition I typed out in my previous post.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Josh, sorry I didn't get it right before, I needed some sleep. I think I have the code as you suggested now, but when I run the strategy in replay it still rejects the order & terminates the strategy. Attached is a picture showing the code, the chart, and the log. I'm frustrated w myself that I can't get a four line piece of code to run correctly.
                  I'm not sure why as soon as the next bar starts at 9:30:00 (before C[0] gets above H[1]) an order is sent?
                  Thanks for your assistance. Rob
                  [IMG]file:///C:/Documents%20and%20Settings/Rob/Desktop/order%20rejected%20and%20strategy%20terminated.jpg[/IMG]
                  Attached Files

                  Comment


                    #10
                    robhef,

                    The condition is as you outlined, but you need to adjust the values yourself. It is exactly as the error message suggests. You cannot place such an order below the market. For instance you cannot place a stop order below the market and that is exactly what you are doing. When price goes to High[1] + TickSize you place the stop 5 ticks below.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Josh & Ben for your patience and explanations. I apologize for the slow replies, I'm often trying to read more about the subject in the help guide or through other posts to get a better understanding. Or am on a mixed up sleep schedule.

                      Your support & knowledge base is the best I've run into - anywhere for any business so far - bar none. Many thanks again, Rob.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Segwin, 05-07-2018, 02:15 PM
                      10 responses
                      1,769 views
                      0 likes
                      Last Post Leafcutter  
                      Started by Rapine Heihei, 04-23-2024, 07:51 PM
                      2 responses
                      30 views
                      0 likes
                      Last Post Max238
                      by Max238
                       
                      Started by Shansen, 08-30-2019, 10:18 PM
                      24 responses
                      943 views
                      0 likes
                      Last Post spwizard  
                      Started by Max238, Today, 01:28 AM
                      0 responses
                      10 views
                      0 likes
                      Last Post Max238
                      by Max238
                       
                      Started by rocketman7, Today, 01:00 AM
                      0 responses
                      7 views
                      0 likes
                      Last Post rocketman7  
                      Working...
                      X