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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      47 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      23 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      33 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      51 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Working...
      X