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

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 -

                  BertrandNinjaTrader Customer Service

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

                      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 lorem, 04-25-2024, 09:18 AM
                        18 responses
                        75 views
                        0 likes
                        Last Post lorem
                        by lorem
                         
                        Started by joselube001, 05-10-2024, 12:17 PM
                        4 responses
                        20 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Started by DawnTreader, 05-08-2024, 05:58 PM
                        21 responses
                        81 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by doihaveto13, Today, 12:46 PM
                        2 responses
                        4 views
                        0 likes
                        Last Post doihaveto13  
                        Started by Vitamite, Today, 12:48 PM
                        1 response
                        9 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Working...
                        X