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

Overfill from two orders

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

    Overfill from two orders

    Hello,

    I got the following error: "An overfill was detected on order...... Action=BuyToCover Limit price=0 Stop price=0 Quantity=1". Apparently a StopLoss was executed exactly at the same time as a BuyToCover order causing the error.

    If this is correct, is there a way to avoid this from happening again when these two orders execute at the same time? Thanks

    #2
    Hello 2Look4me,

    Thank you for your note.

    This case would be resolved through custom debugging of the users script to determine exactly why the Over-Fills occurred.

    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.

    Your NinjaScript / C# Code will always be logically processed and evaluate according to your set logic – this can of course lead to unexpected results at times, thus we would suggest to simplify and debug your code to better understand the event sequence it would go through - unfortunately we cannot offer such debug or code modification services here, but please see the provided resources below to help you proceed productively :

    First of all you would want to use Print() statements to verify values are what you expect - Debugging your NinjaScript code.

    For strategies add TraceOrders = true to your Initialize() method and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders

    It may also help to add drawing objects to your chart for signal and condition confirmation - Drawing Objects.

    If you would prefer the debug assist of a professional NinjaScript consultant, please let us know and we can provide you a list of third parties.

    Please let me know if you have any questions.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi Alan,
      Thanks for the reply. Perhaps I didn't explain it clearly. I mentioned:
      a StopLoss was executed exactly at the same time as a BuyToCover order causing the error.
      So, I did the debugging and noticed that a StopLoss occurred at 7:53:28 and immediately a BuyToCover occurred also at 7:53:28 creating the "Overfill error".

      Therefore, under these circumstance is there a way to avoid a similar overfill error?

      Comment


        #4
        Hello 2Look4me,

        Are you using the managed or unmanaged approach?

        Are you using a StopLoss method in addition to having logic written to close your position when certain conditions are met? For example a stop of 5 ticks in addition to some if statement that exits your position if that if statement becomes true as well?

        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Unmanaged strategy with StopLoss method and an if statement as below:
          Code:
          protected override void Initialize()
                  {            
                      SetStopLoss(CalculationMode.Ticks,20);           
                  }
          
          protected override void OnBarUpdate()
                  {
          
                       if (Position.MarketPosition == MarketPosition.Short)
                          {
                              if(Statement A)
                              {
                                  ExitShort();
                              }
                          }
                  }
          Thanks again

          Comment


            #6
            Hello 2Look4me,

            You might consider adding logic which would disable your exit call if within x distance of your stop loss order to prevent this from happening. Or you could build logic which would handle an overfill.

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by kevinenergy, 02-17-2023, 12:42 PM
            115 responses
            2,699 views
            1 like
            Last Post kevinenergy  
            Started by prdecast, Today, 06:07 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by Christopher_R, Today, 12:29 AM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by chartchart, 05-19-2021, 04:14 PM
            3 responses
            577 views
            1 like
            Last Post NinjaTrader_Gaby  
            Started by bsbisme, Yesterday, 02:08 PM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X