Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Prefer Stoploss fill before Profit fill in ambiguous cases

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

    Prefer Stoploss fill before Profit fill in ambiguous cases

    In my backtest result I see, that when one bar goes across
    both Profit and Stoploss
    , then Profit as filled and whole trade is reported as profitable trade.

    This simulates naive optimistic scenario, which I would like to avoid
    and prefer filling stoploss in this ambiguous case.

    How can be achieved that (using Unmanaged mode)?

    My current idea is to write my custom FillType, where I will check if next bar goes across both Profit and Stoploss, so I will block filling Profit in this special case to make Stoploss be filled instead...
    Last edited by misova; 12-10-2015, 02:32 PM.

    #2
    I think I found the solution after some research and analysis.
    I am not completely sure, so maybe NT guys can confirm it is the right direction
    or put more light on this topic.

    I see, this is more complex problem, that needs 2 levels of custom logic:
    1. custom logic to classify every order as Entry-order / Profit-order / Stoploss-order
    2. custom logic how to associate Stoploss-order to every Profit-order.


    If you know the 2 things above, then we can program our custom FillType,
    which will check, if the processed order is of type Profit.
    If Yes -> then we check if ambiguous situation happens (PT & SL can be both filled in next bar)
    and if ambiguous case happened, then just skip filling the Profit-order (next fill of Stoploss-order will automatically follow).

    This way we can achieve, that Stoploss-order will be always filled before Profit-order.

    Comment


      #3
      Hello,

      Thank you for the questions.

      You are correct, a fill type would be needed to modify how the fills occur.

      Regarding your two questions, I would not have specific syntax I could provide for these but you could certainly create your own fill type with whatever logic you like.

      You can see the code used for the default types in the folderocuments\NinjaTrader 7\bin\Custom\Type as @DefaultFillType.cs and @LiberalFillType.cs.

      These do contain an override which provide the Order object so you can determine what type of order it was etc.

      I look forward to being of further assistance.

      Comment


        #4
        Thank you for additional explanation.

        I have implemented custom fill-type today and it really works great.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X