Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with ExitShortStop

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

    Problem with ExitShortStop

    I am in the process of developing a new strategy. When various conditions are met, the strategy will hold a short position overnight and then on the market open, will set limit and stop orders.

    In this particular case, the stop order causes an error, as reported in the Control Center Log tab, "the stop price is less than or equal to the close price of the current bar".

    Such a situation is a "normal" possibility..... and, I guess I expected the stop order to simply fill immediately at the best price possible... i.e. taking the strategy out of its short position....

    This is occurring in a simulation account and while the strategy is operating on back bars (i.e. not real-time), has exitonclose = false, and uses program calls that allow the orders to endure bar to bar.

    My questions are:
    1)Why am I wrong in expecting an immediate fill under these circumstances?
    2)Will this be what happens in a live trading account operating in real-time and is it possibly broker dependent?
    3)Will the same thing happen on a limit order? And
    4)Given that it is a normal expected occurrence that the market open stop could immediately be outside the market price, what is the best way to program around a rejected order?

    #2
    TS_Gordo, this is expected as at the time you try to submit the order, it's not a valid one, you could code around this by checking off against the inside current market (bis / ask).

    1. The fill expectation is ok, you just can't submit it the way you thought

    2. Not broker dependent and yes expected so it would happen

    3. Sell limit order would be marketable and thus trigger / fill.

    4. You could disable RealTimeErrorHandling and work with IOrders to 'see' a rejected orderstate, thus allowing you to handle it as you wish -



    Comment


      #3
      Bertrand,

      Thanks for your reply. I need to clarify a couple of your responses, please bear with me....

      re: my question (1) you say: "The fill expectation is ok, you just can't submit it the way you thought".

      Ok, how should I submit it?

      re: my question (3) perhaps I wasn't clear. I was asking will a limit order with a limit price outside the current price be rejected in a similar way?

      Finally, I conclude that I must program around this. My intention is to use the OnOrderUpdate() method to field both rejected limit and stop orders. And I expect the strategy to work the same way in a live trading account in real-time as it does in my simulation account doing back bars.

      Is this correct?

      Comment


        #4
        1. You can't submit stops that will be rejected at the exchange. If you want it to fill, check the close price against your stop price before hand and if the stop < close, place a market order instead.

        2. Limit orders generally will not be rejected unless it is drastically below the bar's price. In that instance, depending on the brokerage, it may or may not be rejected.

        3. You should not expect real-time to behave the same as backtesting. Real-time can yield completely different scenarios than what was seen in backtesting.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          In response to my original submission, NinjaTrader_Bertrand said:
          4. You could disable RealTimeErrorHandling and work with IOrders to 'see' a rejected orderstate, thus allowing you to handle it as you wish -
          And provided the following links:



          I believe I have coded this solution... as shown in these code snippets:

          protected override void Initialize()
          {
          CalculateOnBarClose = true;
          BarsRequired = 0;
          ExitOnClose = false;
          TraceOrders = true;
          RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction; <<<<<
          }
          protected override void OnBarUpdate()
          {
          .
          .
          .
          Print ("---- About to set ExitShortStop @ yesterdaysHighestHighValue + twoTicks=" + stopValue.ToString("0.00"));
          stopOrder = ExitShortStop(0, true, 1, stopValue, "StopOutLong", "ShortPosition");
          if (stopOrder != null) {
          Print ("---- After Set Stop Order: " + stopOrder.ToString());
          } else {
          Print ("---- After Set Stop Order: Null");
          }
          .
          .
          .
          }
          protected override void OnOrderUpdate(IOrder order)
          {
          Print ("Entering OnOrderUpDate W/ " + order.ToString());
          if (stopOrder != null && stopOrder.Token == order.Token) {
          Print ("---- Matched stopOrder Token...");
          if (order.OrderState == OrderState.Rejected) {
          Print ("---- Matched Rejected State...");
          if (inLong) {
          Print ("---- Doing inLong Stuff...");
          ExitLong(0, 1, "ExitLongPosition", "LongPosition");
          CancelOrder(limitOrder);
          } else if (inShort) {
          Print ("--- Doing inShort Stuff...");
          ExitShort(0, 1, "ExitLongPosition", "LongPosition");
          CancelOrder(limitOrder);
          }
          }
          }
          }

          The problem is that as shown by the trace messages in the output window, it appears that the rejected stop order NEVER enters the OnOrderUpdate method:

          ---- About to set ExitShortStop @ yesterdaysHighestHighValue + twoTicks=1069.75
          11/9/2009 09:31:00 Entered internal PlaceOrder() method at 11/9/2009 09:31:00: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1069.75 SignalName='StopOutLong' FromEntrySignal='ShortPosition'

          11/9/2009 09:31:00 Ignored PlaceOrder() method at 11/9/2009 09:31:00: Action=BuyToCover OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1069.75 SignalName='StopOutLong' FromEntrySignal='ShortPosition' Reason='Invalid order price, please see log tab'

          ---- After Set Stop Order: Null

          (OnOrderUpdate is entered on behalf of a limit order, set just before the rejected stop order....)
          Entering OnOrderUpDate W/ Order='NT-00012/Sim101' Name='LimitOutLong' State=PendingSubmit Instrument='ES ##-##' Action=BuyToCover Limit price=1055.5 Stop price=0 Quantity=1 Strategy='TSiDailyTrend' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='b6117aa35f1c479a95487a4c869b78ac' Gtd='12/1/2099 00:00:00'
          Entering OnOrderUpDate W/ Order='NT-00012/Sim101' Name='LimitOutLong' State=Accepted Instrument='ES ##-##' Action=BuyToCover Limit price=1055.5 Stop price=0 Quantity=1 Strategy='TSiDailyTrend' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='b6117aa35f1c479a95487a4c869b78ac' Gtd='12/1/2099 00:00:00'
          Entering OnOrderUpDate W/ Order='NT-00012/Sim101' Name='LimitOutLong' State=Working Instrument='ES ##-##' Action=BuyToCover Limit price=1055.5 Stop price=0 Quantity=1 Strategy='TSiDailyTrend' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='b6117aa35f1c479a95487a4c869b78ac' Gtd='12/1/2099 00:00:00'

          (this line is a subsequent Print.... note it is on a bar that is 10 minutes later.)
          Closing HotWindow On Bar Number 007388 @ 2009/11/09-09:41:00;
          Last edited by ts_gordo; 01-15-2010, 09:16 AM. Reason: submission not complete

          Comment


            #6
            ts_gordo, do you check for the rejected orderstate of your IOrder in the OnOrderUpdate()?

            Comment


              #7
              Please note changes to post #5.... I don't know why it submitted while I was in the middle of entering it.

              Comment


                #8
                ts_gordo, the order was never rejected as it was never submitted (ignored order, never entered OnOrderUpdate()).

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                558 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                324 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                545 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                547 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X