Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged SubmitOrder is filling once in historical and twice in live

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

    Unmanaged SubmitOrder is filling once in historical and twice in live

    Hi,

    I have a strategy that worked out nicely in historical / strategy analyzer tests, but when using it in 'live' trading using Sim101 it is suddenly showing every order entry as occuring twice at the exact same instance.

    Here are the background details:

    Using MB data feed, calculate on bar close = true

    OnBarUpdate() it calls a method called CheckForPullBack()

    CheckForPullBack() looks for entry conditions, then does this:

    if(EntryOrder == null)
    EntryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, TradeSizeInt, 0, EntryLevel, "","LongPullBack1");

    if(EntryOrder != null)
    {
    CancelOrder(EntryOrder);
    EntryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Stop, TradeSizeInt, 0, EntryLevel, "","LongPullBack1");
    }

    The reason why it checks for != null and cancels is because I'm working with buy stops that may result in old ones needing to be removed before the revised order is issued.

    My best guess for now is that somehow OnBarUpdate is being called twice and triggering two SubmitOrders even though I have CalculateOnBarClose = true, but that doesn't seem quite it either. Anyone have any thoughts?

    Thanks!

    #2
    Hi RunnrX, I would suggest to add debug prints into the code to be able to correlate those then with the TraceOrders output to see exactly which event sequence leads to the undesired outcome for you, OnBarUpdate() should not get called twice, is this a Single or MultiSeries script you're working with?

    Comment


      #3
      (It's a single series in this case)

      Thank you for this suggestion. After sitting and looking at the output box for a few minutes and wondering why I was seeing it submit an entry order, then cancel the entry order, then submit it again, I finally had my epiphany: It was because of the way I had my code laid out:

      if EntryOrder == null
      EntryOrder = SubmitOrder

      if EntryOrder != null
      Cancel EntryOrder
      EntryOrder = SubmitOrder

      It was filling EntryOrder with a value then immediately cancelling it and refilling it.

      Now I have it as

      If EntryOrder != null
      CancelOrder(EntryOrder)

      EntryOrder = SubmitOrder...

      This way safely clears out any old pending buy stop orders first before submitting new order, just once like it is supposed to. Thanks for saving the day again NinjaTrader_Bertrand!

      Comment


        #4
        You're welcome and thanks for posting your resolution, it makes perfect sense.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        566 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        548 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X