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

Calling SetStopLoss again after Rejection from Exchange

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

    Calling SetStopLoss again after Rejection from Exchange

    Hi

    I am calling SetStopLoss() to set a non-trailing stop. I have my logic to set to break even. Sometimes it gets rejected - this is fine.

    But the problem is that after the rejection all subsequent calls to SetStopLoss() is being ignored, and I am unable to set a StopLoss at all. This is unacceptable.

    Also, this is a problem even on Sim. For example, after getting the error "Sell stop or sell stop limit orders can't be placed above the market." all future calls to SetStopLoss() is ignored by NT8. There's no way to set a stop...


    Is this a known bug or is there a workaround for it.











    Last edited by madankumars; 11-18-2019, 11:17 AM.

    #2
    Hello madankumars,

    Thanks for your post.

    Are you ensuring that you are resetting your stop loss by calling SetStopLoss when the strategy is flat before the next Enter order is submitted? You will need to do this since SetStopLoss preps NinjaTrader to submit the next stop loss at this level.

    You can check the example below for demonstration on how setting a stop loss dynamically should be done. If you are still having issues, please attach a modification of this example script that shows how you are hitting this issue following this approach.

    SamplePriceModification - https://ninjatrader.com/support/help...of_stop_lo.htm

    I look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi, thanks for your reply. I saw your sample...

      In my situation, the position is still open. and i want to send another stop loss after the 1st one is rejected

      for example, taking from your sample code :

      protected override void OnBarUpdate()
      {

      // If a long position is open, allow for stop loss modification to breakeven
      if (Position.MarketPosition == MarketPosition.Long)
      {
      // Once the price is greater than entry price+50 ticks, set stop loss to breakeven
      if (Close[0] > Position.AveragePrice + 50 * TickSize)
      {
      SetStopLoss(CalculationMode.Price, Position.AveragePrice);
      }
      }


      If the SetStopLoss() gets rejected for whatever reason, the next time OnBarUpdate() is called, it needs to submit again, correct? it does not work like that. It gets completely ignored.

      What do we need to do to make sure it submits the order again, if the first time it is rejected?






      Comment


        #4
        Hello madankumars,

        Thanks for your question.

        You could set RealtimeErrorHandling to IgnoreAllErrors, or StopCancelCloseIgnoreRejects, and then trap the rejection in OnOrderUpdate. You can then use an Exit method to submit your Stop Loss order instead of using SetStopLoss.

        For further direction on using OnOrderUpdate, I recommend our SampleOnOrderUpdate strategy.

        SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

        OnOrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm

        RealtimeErrorHandling - https://ninjatrader.com/support/help...orhandling.htm

        Please let me know if there is anything else I can do to help.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi, My strategy is already set to StopCancelCloseIgnoreRejects.

          Can you please tell me exactly what do I need to do in OnOrderUpdate ? I can trap the rejection in OnOrderUpdate. But what exactly do I need to do to ensure SetStopLoss() works again?

          Right now i am using my own logic to exit my position at market, but that is causing lots of slippage because there is no active stop order loss in place.

          Also this is risky because if i get disconnected or if NT crashes/hangs while I have an open position, that means there is basically no stop loss and I have a huge risk.








          Comment


            #6
            Hello madankumars,

            When you trap the rejection within OnOrderUpdate, submit your stop loss using an Exit method. You will need to use the Exit method instead of SetStopLoss because the strategy is already in a position.

            When the strategy is flat, call SetStopLoss again to reset it to an initial level before you call your next Enter method. I have attached an example that can demonstrate submitting a second stop loss on a rejection.

            Please let me know if you have any questions.
            Attached Files
            JimNinjaTrader Customer Service

            Comment


              #7
              Thanks for your response. But i dont want to exit the position using a market order.

              This is what I want:

              1. Enter Long
              2. [Open Position Exists]
              3. Call SetStopLoss() - this gets rejected.
              4. Call SetStopLoss() again - i need to set a new stop loss

              What you are telling me is that I need to go Flat , before calling #4. Otherwise nothing can be done. Did I get that right?


              Comment


                #8
                Hello madankumars,

                SetStopLoss needs to be called when the strategy is flat before it enters to prep NinjaTrader to submit the stop loss to an appropriate level once the associated Enter order fills.

                The test script does the following:

                1. Calls SetStopLoss to set stop loss to an initial level (invalid level to create a rejection.)
                2. Calls EnterLong to enter
                3. Traps the Stop loss's rejection
                4. Calls ExitLongStopMarket to place a stop market order to act as your stop loss which was initially rejected.

                You need to trap when the rejection happens in OnOrderUpdate and use an Exit method to submit the order instead of calling SetStopLoss again.

                Please test the attached script in post #6 for demonstration.

                We look forward to assisting.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by jaybedreamin, Today, 05:56 PM
                0 responses
                7 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                18 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                4 views
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                12 views
                0 likes
                Last Post Javierw.ok  
                Started by timmbbo, Today, 08:59 AM
                2 responses
                13 views
                0 likes
                Last Post bltdavid  
                Working...
                X