Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SL Order gets cancelled almost immediately, why?

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

    SL Order gets cancelled almost immediately, why?

    Hello Support,

    I'm having an issue here with managed orders, I set a small sample where I place a long market order and an SL for it, yet it gets canceled out in the few next ticks.

    Also, TraceOrders doesn't seem to do anything for me, doesn't print anything

    Would appreciate your help, regards

    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class TestOrders: Strategy
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description = """;
                    Name = "Test";
                    IsInstantiatedOnEachOptimizationIteration = false;
                    TraceOrders = true;
                }
                else if (State == State.DataLoaded)
                {
                }
            }
            protected override void OnBarUpdate()
            {
                if (CurrentBar < BarsRequiredToTrade)
                    return;
                if (State != State.Realtime)
                    return;
                if (Position.MarketPosition != MarketPosition.Flat)
                    return;
                EnterLong();
            }
            protected override void OnExecutionUpdate(Execution execution, string execution, double price, int quantity,
                MarketPosition marketPosition, string orderId, DateTime time)
            {
                if (!execution.IsEntryStrategy || !execution.Order.IsLong)
                    return;
    
                //Either setting Low[0] or a fixed prie it gets cancelled
                ExitLongStopMarket(Low[0]);
            }
            protected override void OnOrderTrace(DateTime timestamp, string message)
            {
                Print(string.Format("{0} {1}", timestamp, message));
            }
        }
    }

    #2
    My bad, as I just read with managed orders they get canceled on every bar.

    Still, the TraceOrders don't seem to do anything for me.

    Regards,

    Comment


      #3
      Hello Waxavi,

      When orders are submitted without the isLiveUntilCancelled bool set to true, this will default to false and the order will be automatically cancelled when the submission bar closes.

      ExitLongStopMarket(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double stopPrice, string signalName, string fromEntrySignal)
      "
      isLiveUntilCancelled
      The order will NOT expire at the end of a bar but instead remain live until the CancelOrder() method is called or its time in force is reached."


      Any changes in State.SetDefaults require adding a new instance of the script to pull the new defaults. Set TraceOrders = true; in State.Configure to reload without having to add a new instance.
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      58 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      133 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X