• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop order breaks backtester

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

    Stop order breaks backtester

    If I add a stop order in the strategy builder it seems to stop the strategy from processing after placing the first order on a day. For example with no stop 10 orders placed in a day, then add a stop of even 99999999 ticks and now only 1 or 2 orders placed in that day. It just seems to be bugging out the backtest logic for some reason. Help please!

    Ok I think I have found what exactly is conflicting, it seems to be stop orders in strategy builder bug out the strategy if you are using limit entries?
    Last edited by obomana; 04-09-2017, 05:12 AM.

    #2
    Hello obomana,

    In the Strategy Builder Default Properties screen, what is Entries per direction set to?
    What is Entry handling set to?
    Are you using unique signal names for each new order?

    http://ninjatrader.com/support/helpG...opertiesScreen

    http://ninjatrader.com/support/helpG...rdirection.htm

    http://ninjatrader.com/support/helpG...ryhandling.htm

    If you trade is exited does a new order get placed?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi thanks for the fast response.

      I have,
      Entries per direction: 1
      Entry handling: All entries
      Not currently using signal names for orders, this is left blank.
      If the stop is small enough that it triggers then the strategy will continue as normal.

      What it seems to struggle with is exiting then entering in a reverse direction after already in position (but only when a stop is assigned).

      I tried increasing the entries per direction and it would enter more trades in the same direction, but still failed to reverse direction most of the time when signalled.

      Comment


        #4
        Hello obomana,

        The first issue is likely the EntriesPerDirection and Entry handling.

        http://ninjatrader.com/support/forum...564#post501564

        If you add TraceOrders = true; to the State.SetDefaults, are you seeing messages about ignored orders?

        Try setting the EntriesPerDirection to the number of entries you would like in a particular direction.


        The second issue is likely a violation of the managed approach internal handling rules.

        "Methods that generate orders to enter a position will be ignored if:
        A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
        A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction"

        http://ninjatrader.com/support/helpG...antedPositions

        You would need to either allow the stop to exit the trade, or use an entry in the opposite direction to reverse the position. You cannot use both. (And logically you would not want to)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          The problem it would seem is that when there is for example a long stop order active for an open short position then the backtester will ignore any long limit entry orders. It will not close the original short and enter long on triggering as expected.

          When I have no stop orders set the strategy works as expected.

          I have tried naming the short entry limit and long entry limit seperately with a stop named for each one, and changing entry handling to unique entries. But this has made no difference.

          Help much appreciated.

          Comment


            #6
            Hello obomana,

            To be clear you want to have a stop working and place an order to enter in the opposite direction, is this correct?

            You cannot. This violates the internal order handling rules.

            From the help guide:

            "Methods that generate orders to enter a position will be ignored if:
            A position is open and an order submitted by an exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction
            A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction"
            http://ninjatrader.com/support/helpG...antedPositions

            You would need to use the unmanaged approach to do this, or simply call the entry to reverse the position without using an exit order like setstoploss.

            Please let me know if I have not understood correctly.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Yes I think the problem is what you have described because I tried adding a profit target without stop order and I had the same problem.

              It is very important for my strategy however to enter and exit/reverse using a limit entry, while also using a stop loss. It seems strange that this is not possible as normal.

              Is it possible to use this unmanaged approach through the strategy builder?

              Many thanks.

              Comment


                #8
                Hello obomana,

                It is not suggested to have multiple exit orders working for a single entry order. This can lead to both orders filling and can lead to unwanted positions and overfills.

                If you want to reverse the position, it would be suggested to only use the entry in the opposite direction without the stop or target. Or wait until the first position is exited and the position becomes flat before entering into the opposite direction.

                You could also unlock the script use an exit order instead of set method for the stop and targets, and then cancel these using CancelOrder() if you have decided to reverse instead, wait for the protective orders to be cancelled (in OnOrderUpdate) and then submit the order to reverse the position.

                Below is a link to CancelOrder() in the help guide.
                http://ninjatrader.com/support/helpG...hangeorder.htm

                As well as a link to the reference sample on CancelOrder().
                http://ninjatrader.com/support/forum...ad.php?t=18890

                Yes, you could place these orders and any orders at any time using the unmanaged approach as this will not have internal order handling.
                http://ninjatrader.com/support/helpG...d_approach.htm

                No, the Strategy Builder is limited and used for creating simple scripts. Once your strategy needs complexity (such as math), the script needs to be unlocked and coded in the NinjaScript Editor by hand.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you for a very in depth explanation.

                  The only thing I am wondering is that surely a set stop and a limit entry reversal would not be in much danger of both being triggered since they rely on price moving in two different directions?

                  Comment


                    #10
                    Hello obomana,

                    You cannot place an entry order while a position is open and an exit order is working in the managed approach because of the internal order handling rules (whether or not you feel in that specific circumstance your orders would not both fill).

                    You can do this in unmanaged approach.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Uwe1981, Today, 03:41 AM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_Kate  
                    Started by 7robert, Today, 10:07 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post 7robert
                    by 7robert
                     
                    Started by emuns, Today, 09:36 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_PaulH  
                    Started by lmatiukas, Today, 09:31 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post lmatiukas  
                    Started by Irukandji, Today, 09:09 AM
                    3 responses
                    9 views
                    0 likes
                    Last Post NinjaTrader_PatrickG  
                    Working...
                    X