Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calling SetStopLoss again after Rejection from Exchange

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

    #16
    Hello Ulises,

    The script you have provided submits the stop orders at an invalid price.

    A sell stop order must be submitted with the stop price below the current bid price. You are placing these at the Close plus 15 ticks which is most likely far above the current bid and is an invalid price for a sell stop order.


    Below is a link to a video of testing the script.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Yes, that's the whole point, to get the order rejected, in order to trigger the backup stop loss. That comes from earlier in the thread. Its meant to put to backup stop loss orders, one for each entry.
      ulisesguerrero
      NinjaTrader Ecosystem Vendor - Thrifty Coders

      Comment


        #18
        Hello ulisesguerrero,

        If you have submitted a working order like a stop order with an Exit method, any further Set method calls will be ignored:

        From the Desktop SDK:
        Set() methods that generate orders to exit a position will be ignored if:
        A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active
        Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


        As a set method would be ignored if there is a working ExitLongStopMarket() order, why try and mix and match set methods with exit methods? I would suggest just using exit methods.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Hello Chelsea,

          There seems to be a misunderstanding. The idea is to submit a stop when the first one is rejected. So the ExitStop function is used to do that. It works fine for a single entry, but it doesn't work for two entries L1, L2. Please review the thread to clear up any misunderstanding.

          It works fine if its only L1, but with this sample code, it stops working because there's L1 and L2.

          Regards
          Ulises
          ulisesguerrero
          NinjaTrader Ecosystem Vendor - Thrifty Coders

          Comment


            #20
            Hello Ulises,

            A set method submits a stop, it is rejected.
            Immediately an ExitLongStopMarket() submits a stop, this is accepted.
            A second set method attempts to submit a stop - this is not allowed as there is a working Exit method order so the order is ignored.

            Can you clarify what I am not understanding?

            "The idea is to submit a stop when the first one is rejected"

            Then do this with an exit order method, that is rejected, and then replaced. Not with a set method as calling a set method when there is a working exit method will cause the set method to be ignored.

            "Please review the thread to clear up any misunderstanding."

            I've re-reviewed the thread and you are still violating the internal order handling rules. Can you clarify what I am not understanding?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Hello Chelsea,

              The original problem is very simple, I have two entries. And I just need to trigger a stop for each in case the original stop is rejected. Any way to do that with managed orders?

              Regards
              Ulises
              ulisesguerrero
              NinjaTrader Ecosystem Vendor - Thrifty Coders

              Comment


                #22
                Hello Ulises,

                Yes, when using Exit methods only as directed in post # 18.

                Submit the stop with an Exit method when the entry fills.

                If the Exit is rejected, detect this is detected and submit a replacement (with a valid price).

                Do not use Set methods.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #23
                  Thank you Chelsea, here's the updated working code in case anyone is interested:

                  protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice,
                  int quantity, int filled, double averageFillPrice,
                  Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment)
                  {
                  Print($"{time} - Order Update: {order.Name} ({order.FromEntrySignal}) - State: {orderState}");

                  if(order.FromEntrySignal == "L1" && order.Name == "Stop Loss" && orderState == OrderState.Rejected)
                  {
                  Print("L1 Stop Loss Rejected - Placing Emergency Stop");
                  ExitLongStopMarket(0, true, 1, Position.AveragePrice - 5 * TickSize, "Emergency Stop Loss1", "L1");
                  }

                  if(order.FromEntrySignal == "L2" && order.Name == "Stop Loss" && orderState == OrderState.Rejected)
                  {
                  Print("L2 Stop Loss Rejected - Placing Emergency Stop");
                  ExitLongStopMarket(0, true, 1, Position.AveragePrice - 5 * TickSize, "Emergency Stop Loss2", "L2");
                  }
                  }

                  protected override void OnBarUpdate()
                  {
                  if (State == State.Realtime && Position.MarketPosition == MarketPosition.Flat)
                  {
                  // L1 Entry with stop loss
                  double l1StopPrice = Close[0] + 15 * TickSize;
                  double l2StopPrice = Close[0] + 15 * TickSize;


                  EnterLong(1, "L1");
                  Print($"L1 Entry at {Close[0]} with Stop Loss at {l1StopPrice}");

                  // L2 Entry with stop loss
                  EnterLong(1, "L2");
                  Print($"L2 Entry at {Close[0]} with Stop Loss at {l2StopPrice}");

                  ExitLongStopMarket(0, true, 1, Position.AveragePrice + 15 * TickSize, "Stop Loss", "L1");
                  ExitLongStopMarket(0, true, 1, Position.AveragePrice + 15 * TickSize, "Stop Loss", "L2");
                  }
                  }​
                  ulisesguerrero
                  NinjaTrader Ecosystem Vendor - Thrifty Coders

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Pointtoni, Yesterday, 11:41 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post Pointtoni  
                  Started by DayTradingDEMON, Yesterday, 02:10 PM
                  2 responses
                  20 views
                  0 likes
                  Last Post DayTradingDEMON  
                  Started by Marble, 03-20-2025, 05:00 AM
                  7 responses
                  34 views
                  0 likes
                  Last Post Marble
                  by Marble
                   
                  Started by laketrader, 03-10-2025, 07:20 AM
                  6 responses
                  59 views
                  0 likes
                  Last Post laketrader  
                  Started by clintonbullocks15, Yesterday, 07:47 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post clintonbullocks15  
                  Working...
                  X