Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLongLimit+ExitLongLimit+ExitLongStop problem

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

    EnterLongLimit+ExitLongLimit+ExitLongStop problem

    I'm backtesting on historical 1 day bars:

    One day I opened long limit order:
    entryOrderLong = EnterLongLimit(DefaultQuantity, sigPrice, "MyEntryLong");

    and immediately opened long profit order:
    targetOrderLong = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + varTP * TickSize, "MyTargetLong", "MyEntryLong");

    After few days occured signal for stop limit order:
    stopOrderLong = ExitLongStop(0, true, Position.Quantity, Position.AvgPrice, "MyStopLong", "MyEntryLong");

    Now I'm very confused why my entryOrderLong was closed the same day?
    Low price for that day was above stopOrderLong and high price was below targetOrderLong price!

    Below is Output window from that day:

    Code:
    2008-07-23 00:00:00 Entered internal PlaceOrder() method at 2008-07-23 00:00:00: Action=Sell OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=213,23 SignalName='MyStopLong' FromEntrySignal='MyEntryLong'
    2008-07-23 00:00:00 Market Position: Long 1
    2008-07-23 00:00:00 OrderUpdate: Order='NT-00048/Back101' Name='MyStopLong' State=PendingSubmit Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=213,23 Quantity=1 Strategy='EMA1_W2' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='011e12a296e64554a0032f70e470ddf3' Gtd='2099-12-01 00:00:00'
    2008-07-23 00:00:00 OrderUpdate: Order='NT-00048/Back101' Name='MyStopLong' State=Accepted Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=213,23 Quantity=1 Strategy='EMA1_W2' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='011e12a296e64554a0032f70e470ddf3' Gtd='2099-12-01 00:00:00'
    2008-07-23 00:00:00 OrderUpdate: Order='NT-00048/Back101' Name='MyStopLong' State=Working Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=213,23 Quantity=1 Strategy='EMA1_W2' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='011e12a296e64554a0032f70e470ddf3' Gtd='2099-12-01 00:00:00'
    [B][COLOR=Red]2008-07-23 00:00:00 Cancelled pending exit order, since associated position is closed[/COLOR][/B]: Order='NT-00047/Back101' Name='MyTargetLong' State=Working Instrument='$GBPJPY' Action=Sell Limit price=216,23 Stop price=0 Quantity=1 Strategy='EMA1_W2' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='79d27ee1971f46c695e421de43d6eadb' Gtd='2099-12-01 00:00:00'
    2008-07-23 00:00:00 OrderUpdate: Order='NT-00047/Back101' Name='MyTargetLong' State=PendingCancel Instrument='$GBPJPY' Action=Sell Limit price=216,23 Stop price=0 Quantity=1 Strategy='EMA1_W2' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='79d27ee1971f46c695e421de43d6eadb' Gtd='2099-12-01 00:00:00'
    2008-07-23 00:00:00 OrderUpdate: Order='NT-00047/Back101' Name='MyTargetLong' State=Cancelled Instrument='$GBPJPY' Action=Sell Limit price=216,23 Stop price=0 Quantity=1 Strategy='EMA1_W2' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='79d27ee1971f46c695e421de43d6eadb' Gtd='2099-12-01 00:00:00'
    2008-07-23 00:00:00 OrderUpdate: Order='NT-00048/Back101' Name='MyStopLong' State=Filled Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=213,23 Quantity=1 Strategy='EMA1_W2' Type=Stop Tif=Gtc Oco='' Filled=1 Fill price=213,23 Token='011e12a296e64554a0032f70e470ddf3' Gtd='2099-12-01 00:00:00'
    2008-07-23 00:00:00 Execution: Execution='NT-00033' Instrument='$GBPJPY' Account='Back101' Name='MyStopLong' Exchange=Default Price=213,23 Quantity=1 Market position=Short Commission=0 Order='NT-00048' Time='2008-07-24 00:00:00' Multiplier=1E-05
    Last edited by Argo1; 09-10-2009, 02:06 PM.

    #2
    Argo1,

    Please ensure you have ExitOnClose as false.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh, I've got ExitOnClose = false.

      "my entryOrderLong was closed the same day" means the same day when stop order was created (it's few days after entryOrder was filled)

      but maybe:
      2008-07-23 00:00:00 Cancelled pending exit order, since associated position is closed: Order='NT-00047/Back101' Name='MyTargetLong' State=Working Instrument='$GBPJPY' Action=Sell Limit price=216,23 Stop price=0 Quantity=1 Strategy='EMA1_W2' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='79d27ee1971f46c695e421de43d6eadb' Gtd='2099-12-01 00:00:00'
      is not about entryOrder?
      Last edited by Argo1; 09-10-2009, 02:23 PM.

      Comment


        #4
        Argo1,

        That message is not for your entry, it is for your target order. It means it can't find an open long position to exit any more and that is why it was cancelled. Please check OnExecution/OnOrderUpdate to see what closed the long position.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I don't know if my long entry (MyEntryLong) was closed at 2007-07-23?
          There is no sign of that in log nor chart. Log from first post has messages from OnOrderUpdate() and from OnExecution() for that day:
          Print(Time[0] + " OrderUpdate: " +order.ToString());
          Print(Time[0] + " Execution: " + execution.ToString());

          Maybe internal NT logic cancels target limit order when stop limit order is created?

          In message "Cancelled pending exit order, since associated position is closed", "associated position is closed" means that my MyEntryLong is closed and my MyTargetLong order was cancelled?

          Comment


            #6
            Argo1,

            It would not cancel it unless it got filled. If stop got filled, target will be cancelled. Looking over your logs this is exactly what happened.

            Code:
            2008-07-23 00:00:00 OrderUpdate: Order='NT-00048/Back101' Name='MyStopLong'[SIZE=5][B] State=Filled[/B][/SIZE] Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=213,23 Quantity=1 Strategy='EMA1_W2' Type=Stop Tif=Gtc Oco='' Filled=1 Fill price=213,23 Token='011e12a296e64554a0032f70e470ddf3' Gtd='2099-12-01 00:00:00'
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              But at 2008-07-23 there is no reason for MyStopLong to fill. Reason is at 24th.
              In the strategy Stop order creates when position gets 200 pips profit and sets at position's open price.
              Long position was enter at 213.23.

              At 23rd bar: low=213.47 high=215.88 - there is no price signal for fill stop!
              At 24th bar: low=212.79 high=215.85 - only there is.

              Comment


                #8
                Argo1,

                I don't know what your data looks like, but your logs are saying your stop was filled on 7/23 and everything is accurate to that analysis.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Sorry, there is reason at 23rd for stop order.
                  What I not expected is that this closes my profit order. I only wanted to set stop when position reaches 200 pips profit. Profit should stay. Can I do that without creating new target order?

                  Comment


                    #10
                    If you create a stop and the stop gets filled, there is no more position for the target to close and that is why the target is cancelled. You can create a stop at any point. As long as it doesn't fill, the target will remain in place along with the stop.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      My 1st sentence in post #9 was wrong.
                      Stop order was created on 7/23 with price 213.23.
                      Low price for 7/23 bar is: 213.47, high: 215.88 - so stop couldn't be filled that day.
                      On 7/24 low=212.79 high=215.85 - stop should be filled this day

                      Maybe something wrong is in logs?
                      I use everywhere Time[0] within Print() methods in OnExecute(), onOrderUpdate() etc.

                      Comment


                        #12
                        I looked at "Orders" tab in Strategy Analyzer and there is Stop filled on 7/23 @213.23 -why?
                        On "Executions" tab this order is executed on 7/24 - OK
                        On "Trades" Exit time is 7/24 too - OK

                        Comment


                          #13
                          Not sure I follow, the orders tab shows you when it was placed / orderes, so on the 23th, which is ok. Executed then on the next day, which is also in line with what you report.

                          Comment


                            #14
                            Real execution is on 24th even though in log message execution is on 23th?
                            (2008-07-23 00:00:00 Execution: Execution='NT-00033')

                            Comment


                              #15
                              Not following you. Whatever date is stated on the OnExecution printout is the time of the execution.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              666 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              377 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              110 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              580 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X