Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Partial fill leads to unexpected behavior

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

    Partial fill leads to unexpected behavior

    Hey all,
    I have some issue related to partial fills, which I've been trying to figure out myself, but I guess I need your advise here as I probably lack some understanding of how Managed Approach works.

    So, basically I noticed that each time a partial fill is being executed, right after (see the green line at 7:40:09 and the white line below it) the program (not my code) tries to submit a stop-loss order against the entry using some UNDEFINED by me market stop-loss price that is always in the wrong direction (like,if I am buying at $84.06 it will try to put it somewhere above (like in at $90.83 in this fresh example), which leads to the green system error: "Sell-stop or sell stop limit orders can't be placed above the market..." and resulting the position to be cancelled and the whole strategy being disabled as well.

    I have triple checked my code and there is nothing that should trigger such a response and I am unaware why Ninja decides to do that. I've read the related sections in the Ninja manual, but found nothing that could hint about Ninja trying to submit some automatic stop-loss orders when partial fills are executed, nor why it does that incorrectly and causes the error, nor why it decides to cancel the position on its own and disables the strategy.

    Attaching SS.

    Any useful comment is much appreciated ))
    Attached Files

    #2
    Hello DimaFridrich,

    Thanks for your post and welcome to the forums!

    The strategy becomes disabled because of the order submission error. The question is why is the strategy submitting an incorrect stop order. In order to investigate, we will need to review your strategy code. Please post the source code so we can begin our review.

    Alternatively, if you would prefer not to publically post your strategy you are welcome to e-mail it to PlatformSupport[at]NinjaTrader[dot]com Mark the subject atten: Paul. Please include a link to this thread.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I think I found the root of the error, still need your advise

      Thanks,Paul, for your prompt reply!

      OK, after observing the issue, I found out that it never happened in the 1st positions for a specific day, rather on the second order placing when trying to open the 2nd position for the same day.

      Then, after running on the Output data I found that the stop-loss price for the new position for the same symbol was the same as the the previous stop-loss price. This happened automatically and even without me trying to submit a new fresh stoploss. I mean, for some reason NInja was detecting a partial fill for a new position and tried to automatically submit stop-loss using the SAME price it used for prev. entry name (since I use the same Entry name for the same symbol when submitting new entry orders (dunno if this is good actually).

      So anyways,after digging in the tutorial (which is supper helpful in general), I found this:
      "Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position".

      Now, my question is: what do you mean by "you should always reset the stop loss price/offset value"? How am I supposed to do that?

      Thanks!

      Comment


        #4
        Hello DimaFridrich,

        Thanks for your reply.

        Good work debugging what was going on. Based on your initial description I suspected that was the issue but wanted to confirm before advising.

        What you have observed is the expected behavior when using the Set methods for entry/exit. These methods retain the last used value. Typically the set methods are employed in the Initialize section and are set just the once, for example using a 20 tick stop or 20 tick profit target. This means that all entries would use the 20 tick values offset from the Position.AvgPrice.

        In the case of using the set methods in the OnBarUpate() means that you have to take responsibility to set them to a "known" value when you are flat otherwise as you have observed and confirmed they will use the last value used.

        A common way to do this is to test for market position and if flat, set the set method to an initial value using the mode of Ticks, for example:

        if (Position.MarketPosition == MarketPosition.Flat)
        {
        SetStopLoss (CalculationMode.Ticks, 20); // set to initial 20 ticks
        SetProfitTarget (CalculationMode.Ticks, 20);
        }

        Once you are in a position you can then dynamically change the values as needed. It is okay to use Percent, price or ticks as needed. As you can see using Ticks means you do not need to know the specific entry price as the stop/target will 20 ticks on either side (or whatever tick value you wish).

        Alternatively, you can always set the stop & target just before the entry and then adjust as needed, for example:

        if (Your conditions for Long entry)
        {
        SetStopLoss(CalculationMode.Price, Close[0] - 20 * TickSize);
        SetProfitTarget (CalculationMode.Price, Close[0] + 20 *TickSize);
        EnterLong();
        }
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Amazing, I totally got you. Thanks a lot, Paul!

          You were really helpful and now seems I fully understand how it works.

          Will apply this right away

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          23 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          22 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X