Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exitlonglimit problem in backtesting

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

    Exitlonglimit problem in backtesting

    When I enter a limit order like
    ExitLongLimit(
    1,100,"Long1L","Long1");
    during backtesting the order gets executed at 100 when the price hits or is higher than the target. So far so good.

    I do not understand though why the trade is closed at 100, even if the stock traded the whole bar above 100. Eg open 102, low 101, close 103. Imo this should close at 102 right at open. This distorts backtesting results.

    Any recommendations?


    #2
    ... and ExitLongStop() does not execute when the price is staying below the stop price. There may be some logic why it behaves in this manner but so far the reason escapes me. Recommendations?

    Comment


      #3
      Hello,

      Does the bar prior to that exceed 100? If so, that is likely where it is being triggered.
      DenNinjaTrader Customer Service

      Comment


        #4
        Many thanks for coming back!

        Nope, not the case.

        The order is issued and the system executes it on the next bar (with the lines connecting buy and sell ending in the white...). If the limit falls into the trading range of the next bar all is processed correctly.

        Comment


          #5
          Here is the problem with the ExitLongLimit. The Trade in the middle just doesn't make sense. The first one gets executed properly, the second one not so much and the third one hits the stop and all positions are closed.

          Comment


            #6
            Change the fill type to liberal.

            Baruch

            Comment


              #7
              Oh many thanks - that did the trick. Working with daily bars liberal seems to be "a more realistic approach to filling limit and stop limit orders" though the help guide says otherwise.

              Comment


                #8
                Well I spoke too early. Whilst the ExitLongLimit is now working as expected, I cannot get the ExitLongStop to work. Even building an own FillType which sets the FillPrice or changes the order.StopPrice does not help. My guess is the Fill()-function is not called at all as long as the price is below the stop (lowering the stop into the area covered by price executes the stop), eg changing the Fill()-function has no effect.

                Here is the visual: The stop is active at the second bar but is executed on bar 4. I can change the FillPrice at will on bar 4 but I do not manage to get it triggered earlier.

                Any suggestions?

                Comment


                  #9
                  Gwaihir, I would suggest you back to either the default or Liberal supported fill types for the time being, then enable TraceOrders to debug the order behavior your strategy exhibits in this scenario -

                  Comment


                    #10
                    The log says "Order has been ignored since the stop price is greater or equal to close price of the current bar". Which is true. What I'm trying to achieve though is to change the stop price to a valid level and get the stop executed. It seems the log entry is generated before the FillType() is executed. Any ways around this?

                    Comment


                      #11
                      Not sure which FillType() method you refer to - submitting a Sell Stop order above the current price (inside market in realtime) is not a valid order and thus ignored / rejected, you would need to add code to check you submit valid orders at valid prices.

                      Comment


                        #12
                        OK, the problem stems from backtesting as in life trading you could issue the next order after the open. Thank you for your support.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        637 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        366 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        107 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        569 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        571 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X