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 question

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

    Overfill question

    Hi,

    In a strategy using Managed Approach I wrote, I do get sometimes an overfill due to following situation:

    A long position is open, with a limit target set as an exit order. It may happen that the limit price level is very close to the price level where an opposite entry signal occurs. The limit Exit order apparently gets into conflict with the automatic closing of the Long Position due to the EnterShort() method being called around the same time triggered by the short entry Signal.

    I have two options to tackle this:
    1. I do not use limit Exit orders anymore, but do a Close Exit order when Price reaches or exceeds the target. As I am in control of this based on a tick stream, I can control the time from triggering the Exit order until it is executed (filled), and for that time span not allow the opposite entry, but set a flag for the request of the opposite entry and process it once that the Close has been fully filled.
    I am pretty sure to get this stable and robust, just a matter of Setting a flag for the Close out order processing and a flag for a pending entry request.

    2. Keeping the limit order (which would be cool since I can manually adjust the Price Level in my strategy), I could only think of detecting the OnOrderUpdate() Event that the limit is being processed and act the same way as above, i.e. wait until the limit order is filled, and work with a pending request for the opposite entry in that case.
    However, I assume that there is a time of uncertainty stemming from the Server notifiying the Ninja Trader Client program of the limit order being processed in OnOrderUpdate() which makes this approach unusable.
    Is this correct or is Option 2 a viable robust way to avoid the overfill?

    Thanks for opinions and help from more experienced programmers on this platform.

    Cheers,
    Martin

    #2
    Hello Martin,

    Thank you for your inquiry.

    I would suggest checking to see if you are currently in a flat position before running your code to EnterShort().

    Example:
    Code:
    if (Position.MarketPosition == MarketPosition.Flat)
         EnterShort();
    Rather than exiting a long position by just using EnterShort(), it would probably be best to use an ExitLong(), check for a flat position, and then EnterShort() if you wish to revert to enter a short position.

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thanks.

      1. I do not really get how this would help with the issue of the limit order being triggered just before I get a counter-signal for opposite entry.

      2. Just for reversing an entry: May I ask what the advantage will be of your approach since it looks like that the Managed Approach does this automatically in the Background.

      Regards,
      Martin

      Comment


        #4
        Hello Martin,
        1. As your EnterShort() will not be called unless you are in a flat position, this will prevent an EnterShort() from occuring until you are out of a position.

          You could also use a boolean, instead, that will keep track if your exit limit order has fired or not and prevent your EnterShort() from triggering if that boolean variable is true/false and preventing both the exit and entry from occurring at the same time.

        2. Please note that the internal order handling rules do not apply to market orders. You could use that same boolean check to reverse your position as long as the exit was never triggered.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Thanks. I understand the reversing issue, although I have not had any overfill just on the reversing of a Position.

          My real issue is the Limit order being executed so that the cancellation of the Limit by my code upon the reversal entry Comes too late, thus causing the overfill.

          Sorry to be insistent on this, is there a time delay between the Limit execution on the Server and the notification in OnOrderUpdate()? If yes, I will not use Limit orders in this strategy, but do a market Exit order which I can fully control with flags.

          Cheers,
          Martin

          Comment


            #6
            Hello Martin,

            Yes, there can be a delay between sending the order to the brokerage and the exchange and that order's status being updated in OnOrderUpdate().
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              OK, understand. This is valuable Information for me, thank you. I will go an implement the market Exit orders then. I am quite sure to get this stable without overfills.

              Cheers,
              Martin

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ScottW, Today, 06:09 PM
              1 response
              4 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by ScottWalsh, Today, 06:52 PM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by ftsc2022, 10-25-2022, 12:03 PM
              5 responses
              256 views
              0 likes
              Last Post KeyonMatthews  
              Started by Board game geek, 10-29-2023, 12:00 PM
              14 responses
              244 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by Waxavi, 04-19-2024, 02:10 AM
              4 responses
              56 views
              0 likes
              Last Post sonia0101  
              Working...
              X