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

Stop cancelled incorrectly on multiple entires in replay trading

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

    Stop cancelled incorrectly on multiple entires in replay trading

    Hi,

    I am trying to do two entries at the same price with separate targets but the same stop value. My code seems to work find in back testing but suddenly misbehaves in replay. When the stop is hit, only the one stop fires and the other is canceled. So both targets and both stops are canceled instead of just one and you left with an open position without any stops or targets.

    See the following trace information

    Code:
    Date: 10/19/2009 10:00:00 AM Entered Short Trade B(DttwTestSEb) at 1084.75
    Date: 10/19/2009 10:00:00 AM Stop 1089.75 Target 1082.75
    10/19/2009 10:03:24 AM Entered internal PlaceOrder() method at 10/19/2009 10:03:24 AM: Action=BuyToCover OrderType=Stop Quantity=7 LimitPrice=0 StopPrice=1089.75 SignalName='DttwStopB' FromEntrySignal='DttwTestSEb'
    10/19/2009 10:03:24 AM Amended matching order: Action=BuyToCover OrderType=Stop Quantity=7 LimitPrice=0 StopPrice=1089.75 SignalName=DttwStopB' FromEntrySignal='DttwTestSEb'
    10/19/2009 10:03:24 AM Entered internal PlaceOrder() method at 10/19/2009 10:03:24 AM: Action=BuyToCover OrderType=Limit Quantity=7 LimitPrice=1082.75 StopPrice=0 SignalName='DttwTargetB' FromEntrySignal='DttwTestSEb'
    10/19/2009 10:03:24 AM Amended matching order: Action=BuyToCover OrderType=Limit Quantity=7 LimitPrice=1082.75 StopPrice=0 SignalName=DttwTargetB' FromEntrySignal='DttwTestSEb'
    Date: 10/19/2009 10:00:00 AM Entered Short Trade A(DttwTestSEa) at 1084.75
    Date: 10/19/2009 10:00:00 AM Stop 1089.75 Target 1080.75
    10/19/2009 10:03:24 AM Entered internal PlaceOrder() method at 10/19/2009 10:03:24 AM: Action=BuyToCover OrderType=Stop Quantity=10 LimitPrice=0 StopPrice=1089.75 SignalName='DttwStop' FromEntrySignal='DttwTestSEa'
    10/19/2009 10:03:24 AM Amended matching order: Action=BuyToCover OrderType=Stop Quantity=10 LimitPrice=0 StopPrice=1089.75 SignalName=DttwStop' FromEntrySignal='DttwTestSEa'
    10/19/2009 10:03:24 AM Entered internal PlaceOrder() method at 10/19/2009 10:03:24 AM: Action=BuyToCover OrderType=Limit Quantity=10 LimitPrice=1080.75 StopPrice=0 SignalName='DttwTarget' FromEntrySignal='DttwTestSEa'
    10/19/2009 10:03:24 AM Amended matching order: Action=BuyToCover OrderType=Limit Quantity=10 LimitPrice=1080.75 StopPrice=0 SignalName=DttwTarget' FromEntrySignal='DttwTestSEa'
    Date: 10/19/2009 10:00:00 AM Entered Short Trade B(DttwTestSEb) at 1084.75
    Date: 10/19/2009 10:00:00 AM Stop 1089.75 Target 1082.75
    10/19/2009 10:03:24 AM Entered internal PlaceOrder() method at 10/19/2009 10:03:24 AM: Action=BuyToCover OrderType=Stop Quantity=10 LimitPrice=0 StopPrice=1089.75 SignalName='DttwStopB' FromEntrySignal='DttwTestSEb'
    10/19/2009 10:03:24 AM Amended matching order: Action=BuyToCover OrderType=Stop Quantity=10 LimitPrice=0 StopPrice=1089.75 SignalName=DttwStopB' FromEntrySignal='DttwTestSEb'
    10/19/2009 10:03:24 AM Entered internal PlaceOrder() method at 10/19/2009 10:03:24 AM: Action=BuyToCover OrderType=Limit Quantity=10 LimitPrice=1082.75 StopPrice=0 SignalName='DttwTargetB' FromEntrySignal='DttwTestSEb'
    10/19/2009 10:03:24 AM Amended matching order: Action=BuyToCover OrderType=Limit Quantity=10 LimitPrice=1082.75 StopPrice=0 SignalName=DttwTargetB' FromEntrySignal='DttwTestSEb'
    10/19/2009 10:30:43 AM Cancelled pending exit order, since associated position is closed: Order='9466b7d08322440fbea0fe3d7716bd15/Replay101' Name='DttwTarget' State=Working Instrument='ES 12-09' Action=BuyToCover Limit price=1080.75 Stop price=0 Quantity=10 Strategy='DttwTest' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='9466b7d08322440fbea0fe3d7716bd15' Gtd='12/1/2099 12:00:00 AM'
    10/19/2009 10:30:43 AM Cancelled pending exit order, since associated position is closed: Order='77cb060d0c7f42ef8d39ebbc473f2672/Replay101' Name='DttwTargetB' State=Working Instrument='ES 12-09' Action=BuyToCover Limit price=1082.75 Stop price=0 Quantity=10 Strategy='DttwTest' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='77cb060d0c7f42ef8d39ebbc473f2672' Gtd='12/1/2099 12:00:00 AM'
    10/19/2009 10:30:43 AM Cancelled pending exit order, since associated position is closed: Order='7e0391558b3a44a2b5f3f1545cce6a20/Replay101' Name='DttwStopB' State=Working Instrument='ES 12-09' Action=BuyToCover Limit price=0 Stop price=1089.75 Quantity=10 Strategy='DttwTest' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='7e0391558b3a44a2b5f3f1545cce6a20' Gtd='12/1/2099 12:00:00 AM'
    My Entry Code is

    Code:
    entryOrderA = EnterShortLimit(NoContracts/2, shortEntryPrice, "DttwTestSEa");
     entryOrderB = EnterShortLimit(NoContracts/2, shortEntryPrice, "DttwTestSEb");
    Stops are targets are set in OnExecution()

    Code:
    // Place Stops and Targets for Order A when Short
                
                if (entryOrderA != null && entryOrderA.Token == execution.Order.Token  && Position.MarketPosition == MarketPosition.Short)
                {
                    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                    {
                        Print ("Date: "+Time[0]+" Entered Short Trade A("+execution.Name+") at "+execution.Order.AvgFillPrice);
                        Print ("Date: "+Time[0]+" Stop "+(execution.Order.AvgFillPrice + stopTicks * TickSize)+" Target "+(execution.Order.AvgFillPrice - FirstProfitTicks * TickSize));
                        
                        stopOrderA     = ExitShortStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + stopTicks * TickSize, "DttwStop", "DttwTestSEa");
                        targetOrderA = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - FirstProfitTicks * TickSize, "DttwTarget", "DttwTestSEa");
                        
                        // Resets the entryOrder object to null after the order has been filled or partially filled
                        if (execution.Order.OrderState != OrderState.PartFilled)
                        {
                            entryOrderA     = null;
                        }
                    }
                }
    
    // Place Stops and Targets for Order B when Short
                
                if (entryOrderB != null && entryOrderB.Token == execution.Order.Token  && Position.MarketPosition == MarketPosition.Short)
                {
                    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                    {
                        Print ("Date: "+Time[0]+" Entered Short Trade B("+execution.Name+") at "+execution.Order.AvgFillPrice);
                        Print ("Date: "+Time[0]+" Stop "+(execution.Order.AvgFillPrice + stopTicks * TickSize)+" Target "+(execution.Order.AvgFillPrice - SecondProfitTicks * TickSize));
                        
                        stopOrderB     = ExitShortStop(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + stopTicks * TickSize, "DttwStopB", "DttwTestSEb");
                        targetOrderB = ExitShortLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice - SecondProfitTicks * TickSize, "DttwTargetB", "DttwTestSEb");
                        
                        // Resets the entryOrder object to null after the order has been filled or partially filled
                        if (execution.Order.OrderState != OrderState.PartFilled)
                        {
                            entryOrderB     = null;
                        }
                    }
                }
    I do have EntryHandling set in Initialise()

    Code:
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    Any idea why I am seeing this behavior?

    #2
    What are you using for your stop&target handling?
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Its in the second code snippet - see ExitShortStop() and ExitShortLimit(). These are called in OnExecution() when an entry order is detected.

      This code is derived from the SampleOnOrderUpdate strategy found on the website.

      Comment


        #4
        I also note this seems to be similar to the issue described in

        Comment


          #5
          simulatorboy,

          You have likely run into known bugs in 6.5 in terms of scaling out then. They should be resolved in 7.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Are there known workarounds to these issues or does scaling out simply not work in 6.5?

            Comment


              #7
              simulatorboy,

              It looks like you are trying to do a two for two scale-in/out which unfortunately has no known workarounds.
              Josh P.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by xepher101, Yesterday, 12:19 PM
              2 responses
              28 views
              0 likes
              Last Post xepher101  
              Started by thumper57, Today, 04:30 PM
              0 responses
              4 views
              0 likes
              Last Post thumper57  
              Started by OllieFeraher, 05-09-2024, 11:14 AM
              5 responses
              16 views
              0 likes
              Last Post MisterTee  
              Started by jackiegils, Yesterday, 11:05 PM
              1 response
              11 views
              0 likes
              Last Post marcus2300  
              Started by Skifree, Today, 02:50 PM
              0 responses
              8 views
              0 likes
              Last Post Skifree
              by Skifree
               
              Working...
              X