Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Failing to understand why my stop order isnt getting triggered

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

    Failing to understand why my stop order isnt getting triggered

    Good afternoon,

    I am having trouble understanding why my stop isnt getting triggered.

    Here is my strategy code.
    1) I have a short position that was initiated using
    Code:
     EnterShort(trade_quantity,"entry")
    2) I then want to attach a stop loss using the following code
    Code:
            protected override void OnBarUpdate()
            {//ON BAR STARTS
    
                // Handling Existing Shorts
                if (Position.MarketPosition == MarketPosition.Short)
                {                
                    // Stop Loss Adding
                    if ( conditions for placing the stop loss)
                    {   ExitShortStopMarket(trade_quantity,fill_track,"stop","entry");
                        Print("stop placed");
                        Print(Times[0][0]);
                        Print(stopOrder.ToString());}​
    My Print statements are showing in the output window meaning that stopOrder is successfully created.

    stop placed
    2023-11-16 10:42:00 AM
    orderId='NT-00028-1175' account='Backtest' name='stop' orderState=Working instrument='QQQ' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=385.05 quantity=64 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-11-16 10:42:00' gtd='2099-12-01' statementDate='2024-04-27'

    Now notice the stopPrice for the order which is 385.05.
    The below is a screenshot from the strategy. I highlighted in yellow where the "entry" short position was initiated, and then I am highlighting the wick of the candle at 10:48 that goes way pass the 385.05 stop price of the order.

    So why is that stop order not triggered then?


    Click image for larger version

Name:	Screenshot 2024-04-27 101419.jpg
Views:	119
Size:	124.2 KB
ID:	1301245

    Here is also how I assign names for the orders. Including it for completing purposes.

    Code:
            protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
            {
                // Assign order name
                if (order.Name == "entry")
                {    entryOrder = order;}
                else if (order.Name == "stop")
                {    stopOrder = order;}
                
                // Reset stopOrder to null
                if (stopOrder == order && (order.OrderState == OrderState.Filled || stopOrder.OrderState == OrderState.Cancelled))
                {    stopOrder = null;}
           }​

    #2
    Hello Brandon,

    My version is: 8.1.3.0 64-bit

    I am attaching a test script that has the one trade hard coded in.

    Please make sure to set the correct dates for Strat Analyzer: 2023-11-16

    Click image for larger version  Name:	Screenshot 2024-04-28 173911.jpg Views:	16 Size:	216.0 KB ID:	1301363
    Last edited by NinjaTrader_BrandonH; 05-01-2024, 07:26 AM.

    Comment


      #3
      NinjaTrader_BrandonH Hi Brandon, just wanted to check if there were any updates about the stop order?

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      53 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      44 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      49 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X