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

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?







    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.

        Support for the development of custom automated trading strategies using NinjaScript.


        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"



        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"


            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.


                As well as a link to the reference sample on CancelOrder().
                When using NinjaTrader's Enter() and Exit() methods, the default behavior is to automatically expire them at the end of a bar unless they are resubmitted to keep them alive. Sometimes you may want more flexibility in this behavior and wish to submit orders as live-until-cancelled. When orders are submitted as live-until


                Yes, you could place these orders and any orders at any time using the unmanaged approach as this will not have internal order handling.


                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 GLFX005, Today, 03:23 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post GLFX005
                    by GLFX005
                     
                    Started by XXtrader, Yesterday, 11:30 PM
                    2 responses
                    11 views
                    0 likes
                    Last Post XXtrader  
                    Started by Waxavi, Today, 02:10 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post Waxavi
                    by Waxavi
                     
                    Started by TradeForge, Today, 02:09 AM
                    0 responses
                    13 views
                    0 likes
                    Last Post TradeForge  
                    Started by Waxavi, Today, 02:00 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post Waxavi
                    by Waxavi
                     
                    Working...
                    X