Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

problem with contracts doubling up

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

    problem with contracts doubling up

    I have come across an interesting bug in my strategy and i think i need some help with it. Under a very particular set of circumstances, the strategy will actually double up on contracts. I have figured out what exactly is going on, but i don't know how to proceed. a brief summary of my code is:
    if(conditions to go long met)
    {
    EnterLong();
    }
    if(conditions to go short met)
    {
    EnterShort();
    }
    more or less. what should happen is if, for example we are short, when the long conditions are met and EnterLong() is called, it closes out the short and goes long. But, and here are the conditions for the bug, if the stoploss is triggered at the same time the EnterLong() method is called, the stoploss will close out the order, and EnterLong() will close out the order making it up 1, then EnterLong() puts in the order to go long, making it up 2. so in short, when the stoploss and Enterlong() go at the same time, it puts in 3 buy orders instead of 2. is there anyway to prevent this from happening?

    #2
    Hello,

    Thanks for the forum post.

    The only thing you could do if your strategy conditions are sensitive to allow this to occur is that if you are in a position you must program the strategy to cancel the stop loss first before putting in the order to reverse.

    You would need to do this with the below sample, Also, I have attached some below information on OverFills which is also another work for what you have jusst described.



    Over-Fills is a serious issue that can occur when using complex entry conditions that bracket the market in both directions end up with both entries being filled instead of one being cancelled. Over-Fills can also occur when you place a trade quickly hoping to close a position while a prior order to close the same position already had an in-flight execution. The exact scenarios in which an over-fill can occur is highly dependent on the specific strategy programming. By default, NinjaTrader will protect against over-fills even though you are using the Unmanaged approach by halting the strategy, but should you decide to custom program your own over-fill handling it is up to you to either prevent over-fills from being a possibility in your code or by introducing logic to address over-fills should one occur.
    BrettNinjaTrader Product Management

    Comment


      #3
      it looks like what is happening is the overfill that you described, but i am using the managed approach. What is happening (on oil especially since it moves so fast some times) is the stop is hit and is in the process of being filled, then the EnterLong() method thinks that there is no stoploss so it puts in a close position order. After that EnterLong() puts in the order to go long so 3 buy orders go through instead of only 2. i will look into the code you attatched and see if i can fix it with that.
      Last edited by laces2; 03-12-2011, 12:17 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      627 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      359 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      562 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      567 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X