Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLongStop is not carried out

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

    EnterLongStop is not carried out

    Hallo,

    I'm backtesting on daily data and some of the placed
    EnterLongStop orders are expiring without fill although they actually should fill.
    Here is a an example:

    On bar x an entry signal is triggered and an EnterLongStop order is placed.
    The stop is at 1321,3.

    Message in the output window is as follows:

    Entered internal PlaceOrder() method at 19.02.2011 00:00:00: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1321,3 SignalName='entry short' FromEntrySignal=''

    At the same bar the following message shows up after the first one:

    Ignored PlaceOrder() method at 19.02.2011 00:00:00: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1321,3 SignalName=entry short' FromEntrySignal='' Reason='Invalid order price, please see log tab'

    In my opionion the order should be filled or canceled the next bar.

    The next bar has Open=1321,5; High=1329,3; Low=1305,5; Close=1309,4.
    Therefore, the order should be filled and not be ignored/canceled.

    At some bars it works, at some bars it doesn't. When entry is done, exit always works.
    I don't see why entries don't work correct . Whats wrong here?

    The script is as follows:
    Code:
    OnBarUpdate()
    
    //Entry
    
    if entrycondition==true
    {
    buystop = MAX(Close,3)[1];
    entryOrderlong = EnterLongStop(1, buystop,"entry long");
    }
    
    //Exit
    if(BarsSinceEntry("entry long") == 3 && Position.MarketPosition == MarketPosition.Long)
                        {
                            target = NextBar().NextClose[0];
                            stopOrder     = ExitLongStop(target, "Exit", "entry long");
                            targetOrder = ExitLongLimit(target, "Exit", "entry long");
                        }
    
    OnOrderUpdate(IOrder order)
    
    if (entryOrderlong != null && entryOrderlong == order)
                {    
                    // Reset the entryOrder object to null if order was cancelled without any fill
                    if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                    {
                        entryOrderlong = null; 
                    }
                }
    
    OnExecution(IExecution execution)
    
    if (entryOrderlong != null && entryOrderlong == execution.Order)
                {
                    if (execution.Order.OrderState == OrderState.Filled)
                    {
                        
                        // Resets the entryOrder object to null after the order has been filled or partially filled
                        if (execution.Order.OrderState != OrderState.PartFilled)
                        {
                            entryOrderlong     = null;
                        }
                    }
                }
    
    // Reset our stop order and target orders' IOrder objects after our position is closed.
                if ((stopOrder != null && stopOrder == execution.Order) || (targetOrder != null && targetOrder == execution.Order))
                {
                    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
                    {
                        stopOrder = null;
                        targetOrder = null;
                    }
                }
    Short Entries are handeled the same way.
    Thanks in advance!

    #2
    Hi Stephan123,

    Thanks for the post. What is your stop price set in relation to the Close price of the signal bar? Is your buy stop price higher / lower than the close of signal bar?


    Buy stop price needs to be higher than close of signal bar. In real time trading, a buy stop order placed below the last traded price is rejected. In backtesting it is ignored.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Signal Bar: Close=1337,4
      entry signal: short entry
      stop price: 1321,3

      entry order:
      buystop=1321,3;
      EnterShortStop(1,buystop,"entry short");


      Next bar, where entry should be carried out:
      Open=1321,5; High=1329,3; Low=1305,5; Close=1309,4.

      Is this supposed to give a valid entry?

      Comment


        #4
        Signal Bar: Close=1337,4
        buystop=1321,3;

        Your buy stop order is placed below the close price of signal bar, so it's expected that it's ignored in a backtest.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          Signal Bar: Close=1337,4
          buystop=1321,3;

          Your buy stop order is placed below the close price of signal bar, so it's expected that it's ignored in a backtest.
          Although it's a short order?
          What would be the correct syntax,
          if the Close of the signal bar is at price x and I want to wait the price to decrease
          to a lower level y to enter the short trade?

          Comment


            #6
            If it's EnterLongStop(), then it's a buy order, not a sell order. Below are the details of order placement and ignored that you had in your first post.

            For sell stop orders, it's the reverse. They should be placed lower than the last traded price. (In a backtest, Close[0] of signal bar is used for "last traded price")

            You may be looking to place limit orders in these situations instead. For practice, you could use a Superdom and place all order types in both columns, both directions, and see the expected handling.


            ===
            Entered internal PlaceOrder() method at 19.02.2011 00:00:00: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1321,3 SignalName='entry short' FromEntrySignal=''

            Ignored PlaceOrder() method at 19.02.2011 00:00:00: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1321,3 SignalName=entry short' FromEntrySignal='' Reason='Invalid order price, please see log tab'
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Indeed,

              I had entered a long entry by mistake due to some copy and paste error.
              Doing it with EnterShortStop() for short entries works correct.

              However - Exit doesn't always work. Exit is suppposed to happen at the fifth bar
              after entry. There are occasions where this doesn't happen.

              One example:

              Entry is done via
              Code:
              buystop = 1461,6
              entryOrdershort = EnterShortStop(1, buystop,"entry short");
              Works fine so far.

              Exit is done via:
              Code:
              if(BarsSinceEntry("entry short") == 3 && Position.MarketPosition == MarketPosition.Short)
                                  {
                                      target = 1421.2;
                                      stopOrder     = ExitShortStop(target, "Exit", "entry short");
                                      targetOrder = ExitShortLimit(target, "Exit", "entry short");
                                  }
              According to the output window both buy to cover orders are correctly placed .
              The stop order is ignored because the Close of the bar where the order is placed is higher than the stop price.
              However, the limit order should be filled, but it isn't.
              The bar where exit should happen:

              Open=1437,2
              High=1439,6
              Low=1419,5
              Close=1421,2

              Limit price is 1421.2; so it actually should be filled.
              At the bar where both buy to cover orders are placed a buy stop order is placed as well.
              However, its stop price is not hit at the next bar.
              Don't know if this hinders the buy to cover limit order from being filled.

              What's wrong here?

              Thanks in advance. Stephan

              Comment


                #8
                What are the trace orders messages related to these two orders? Why are you submitting both stop and limit orders at the same price?
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_RyanM View Post
                  What are the trace orders messages related to these two orders? Why are you submitting both stop and limit orders at the same price?
                  The messages:

                  Entered internal PlaceOrder() method at 15.12.2007 00:00:00: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1464,9 SignalName='entry long' FromEntrySignal=''

                  Entered internal PlaceOrder() method at 15.12.2007 00:00:00: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=1421,2 SignalName='Exit' FromEntrySignal='entry short'

                  Ignored PlaceOrder() method at 15.12.2007 00:00:00: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=1421,2 SignalName='Exit' FromEntrySignal='entry short' Reason='Invalid order price, please see log tab'

                  Entered internal PlaceOrder() method at 15.12.2007 00:00:00: BarsInProgress=0 Action=BuyToCover OrderType=Limit Quantity=0 LimitPrice=1421,2 StopPrice=0 SignalName='Exit' FromEntrySignal='entry short'

                  At the next bar no short exit happens.

                  I place both limit and stop order to force the exit at a certain price, not evaluating if the Close of the current bar is higher or lower than that stop/limit price.
                  One of the orders should always be canceled and the other order will always be carried out, if the specified price is hit within the next bar.

                  But-it does not always work, only in most cases.

                  Comment


                    #10
                    From that output you posted, it doesn't look like this order is ever submitted. There are no limit orders.

                    targetOrder = ExitShortLimit(target, "Exit", "entry short");

                    It doesn't make sense to place both stop and limit orders at the same price. This isn't something you would do in live trading, and there's a better way of accomplishing your goals in a backtest.

                    I place both limit and stop order to force the exit at a certain price, not evaluating if the Close of the current bar is higher or lower than that stop/limit price.
                    For this I would use a single limit order, and set your historical fill processing as liberal. Details of this below:


                    Liberal
                    An algorithm that takes a liberal approach to filling limit and stop limit orders.
                    • Limit orders fill if the limit price was touched
                    • On gap down bars, buy limit orders will fill at the high of the gap down bar
                    • On gap up bars, sell limit orders will fill at the low of the gap up bar
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_RyanM View Post
                      From that output you posted, it doesn't look like this order is ever submitted. There are no limit orders.

                      targetOrder = ExitShortLimit(target, "Exit", "entry short");
                      Why is the order not submitted?

                      I use

                      Code:
                      if(BarsSinceEntry("entry short") == 3 && Position.MarketPosition == MarketPosition.Short)
                                          {
                                              target = 1421,2;
                                              stopOrder     = ExitShortStop(target, "Exit", "entry short");
                                              targetOrder = ExitShortLimit(target, "Exit", "entry short");
                                          }
                      I use both orders to force the exit at the Close of a certain bar using a subroutine
                      to get the next Close into the variable target. This is a work-around of a function which is doing "Exit on Close", both if the Close of the Exit bar is higher or lower than the
                      actual price. It works fine when i use it within the entry bar with
                      OnExecution(IExecution execution).

                      Just within OnBarUpdate it doesn't work. What's the reason?

                      Comment


                        #12
                        What messages are there related to the order? The only way to know how your strategy responds to the order methods is to use TraceOrders output. Your strategy needs to be simplified so you can follow any relevant messages.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_RyanM View Post
                          What messages are there related to the order? The only way to know how your strategy responds to the order methods is to use TraceOrders output. Your strategy needs to be simplified so you can follow any relevant messages.
                          It's the messages from above:

                          Entered internal PlaceOrder() method at 15.12.2007 00:00:00: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=1421,2 SignalName='Exit' FromEntrySignal='entry short'

                          Ignored PlaceOrder() method at 15.12.2007 00:00:00: Action=BuyToCover OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=1421,2 SignalName='Exit' FromEntrySignal='entry short' Reason='Invalid order price, please see log tab'

                          Entered internal PlaceOrder() method at 15.12.2007 00:00:00: BarsInProgress=0 Action=BuyToCover OrderType=Limit Quantity=0 LimitPrice=1421,2 StopPrice=0 SignalName='Exit' FromEntrySignal='entry short'

                          Seems like both orders are placed, one is canceled but the other one not filled.
                          Don't know how to simplify any further.

                          Comment


                            #14
                            After it's entered, there are no further messages related to the order? You should see it either ignored, filled, or cancelled. I have no explanation if there are no further messages. We would be interested in reproducing this setup so we can see this here. Please send a note to support 'at' ninjatrader 'dot' com along with the strategy and a screenshot of the settings used in the backtest. Indicate your data provider and time zone as well and we should then be able to setup the same.
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_RyanM View Post
                              After it's entered, there are no further messages related to the order? You should see it either ignored, filled, or cancelled.
                              Those are the following messages.
                              None of them seems related to the buy to cover orders.
                              I will provide a test sample of the issue.
                              Thanks in advance
                              Stephan

                              18.12.2007 00:00:00 Entered internal PlaceOrder() method at 18.12.2007 00:00:00: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1464,9 SignalName='entry long' FromEntrySignal=''
                              18.12.2007 00:00:00 Ignore order amendment: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1464,9 SignalName=entry long' FromEntrySignal='' Reason='Order already has this stop price/limit price/quantity'

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              672 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              577 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X