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

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.
      JesseNinjaTrader Customer Service

      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 yertle, Yesterday, 08:38 AM
        7 responses
        28 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        21 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        4 views
        0 likes
        Last Post funk10101  
        Started by gravdigaz6, Yesterday, 11:40 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by MarianApalaghiei, Yesterday, 10:49 PM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X