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

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?
    BertrandNinjaTrader Customer Service

    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.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by aa731, Today, 02:54 AM
        0 responses
        4 views
        0 likes
        Last Post aa731
        by aa731
         
        Started by thanajo, 05-04-2021, 02:11 AM
        3 responses
        470 views
        0 likes
        Last Post tradingnasdaqprueba  
        Started by Christopher_R, Today, 12:29 AM
        0 responses
        10 views
        0 likes
        Last Post Christopher_R  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        166 responses
        2,237 views
        0 likes
        Last Post sidlercom80  
        Started by thread, Yesterday, 11:58 PM
        0 responses
        5 views
        0 likes
        Last Post thread
        by thread
         
        Working...
        X