Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order stop/Profit target bug in back testing?

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

    Order stop/Profit target bug in back testing?

    Hello,

    I am experiencing some weirdness in backtesting, so decided to try some _very_ simple things to test.

    For instance. On FDAX 12-17, I am setting a simple buy on a pullback. I have a simple test stop loss and target as follows. This is for test purposes only. Not a real system.

    Code:
    				Stop					= 10;
    				Target					= 20;
    			}
    			else if (State == State.Configure)
    			{
    				SetStopLoss("", CalculationMode.Ticks, Stop, false);
    				SetProfitTarget("", CalculationMode.Ticks, Target);
    			}
    The entry is a simple EnterLong(Convert.ToInt32(DefaultQuantity), "");

    Now, if using strategy analyser to test, if you have 'High' selected in order fill resolution, stops and target are _never_ hit. The entry simply closes on the session close. If you set order fill resolution to 'fastest', stops and targets are hit as expected! It is somewhat bizarre behaviour and I have a few things like this which is making any back testing I do pointless.

    I am running the latest NT8 8.0.11.0 64-bit (Standard).

    I can think of no reason changing tom high to standard should have this effect.

    Any ideas?

    #2
    Hello pjsmith,

    Thanks for opening the thread.

    I'm seeing the same behavior on my end and I've reported the matter further. I'll update this post once I have additional information.

    Thanks for noticing and bringing this to our attention!
    JimNinjaTrader Customer Service

    Comment


      #3
      Release bug

      Hello Jim,

      How long will it take to resolve this serious bug?

      Regards,
      Felix

      Comment


        #4
        Hello FForrer,

        I can't comment on release cycles and ETA's as these are almost always subject to change.

        I have gotten word back on the issue though. It has been confirmed as a bug by our QA team and is being tracked with the ticket ID: NTEIGHT-12342 Upon implementation the ticket ID for the fix can be found publicly on the Release Notes page of the help guide. I'll provide a link below.

        Release Notes: https://ninjatrader.com/support/help...ease_notes.htm

        If there is anything else I can do to be of further help, please let me know.
        JimNinjaTrader Customer Service

        Comment


          #5
          Let's hope it is days, not weeks. Back-testing of any worth is broken until it is resolved. If there is a way around it, please let me know. I have projects I want to get off the board. Please do express to the dev team that this is a 'critical' bug that is preventing use of the software.

          Comment


            #6
            Other methods to replace targets and stops as well as adding tick data series do not resolve the problem, too.

            Comment


              #7
              Hello FForrer,

              I'll make sure that note is included with the issue. So we can make sure it is tested, could you be more specific on what you did differently to replace the stops and targets that still did not work?
              Last edited by NinjaTrader_Jim; 12-15-2017, 08:26 AM.
              JimNinjaTrader Customer Service

              Comment


                #8
                Hello Jim,

                I replaced the profit target by ExitLongLimit / ExitShortLimit and the stop loss by ExitLongStopMarket / ExitShortStopMarket.



                /// Set stop loss and profit target

                protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
                {
                if (position.MarketPosition == MarketPosition.Long)
                {
                ExitLongStopMarket(position.AveragePrice - (50 * TickSize));
                ExitLongLimit(position.AveragePrice + (50 * TickSize));
                }
                else if (position.MarketPosition == MarketPosition.Short)
                {
                ExitShortStopMarket(position.AveragePrice + (50 * TickSize));
                ExitShortLimit(position.AveragePrice - (50 * TickSize));
                }
                }

                Comment


                  #9
                  Hello FForrer and pjsmith,

                  @Forrer, your suggested workaround would be valid as long as the Advanced Order Handling rules are followed. If you are not using the isLiveUntilCanceled overload, the order will have to be submitted on every OnBarUpdate() iteration. If you use the overload and set isLiveUntilCanceled to true, the orders will stay active when submitted from OnPositionUpdate() and you will not have to resend the order every OBU iteration.

                  Testing the following is working fine for me:
                  Code:
                  protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
                  {
                  	if (position.MarketPosition == MarketPosition.Long)
                  	{
                  		ExitLongStopMarket(0, true, position.Quantity, position.AveragePrice - (5 * TickSize), "ExitLongStopMarket", "ShortEntry");
                  		ExitLongLimit(0, true, position.Quantity, position.AveragePrice + (5 * TickSize), "ExitLongLimit", "ShortEntry");
                  	}
                  	else if (position.MarketPosition == MarketPosition.Short)
                  	{
                  		ExitShortStopMarket(0, true, position.Quantity, position.AveragePrice + (5 * TickSize), "ExitShortStopMarket", "ShortEntry");
                  		ExitShortLimit(0, true, position.Quantity, position.AveragePrice - (5 * TickSize), "ExitShortLimit", "ShortEntry");
                  	}
                  }
                  I'll include publicly available documentation links to the items used in the code above for the forum's reference.

                  OnPositionUpdate() - https://ninjatrader.com/support/help...tionupdate.htm

                  Advanced Order Handling (Live Until Canceled Orders) - https://ninjatrader.com/support/help...ancelledOrders

                  Please let me know if there is anything else I can do to help.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    Hello Jim,

                    Thank you for your reply. You're right and your code works.

                    In my former strategy, where I have been used to set a profit target and stop loss, I coded a dynamic approach regarding the profit target, that means under certain circumstances the strategy increased the profit target. I tried to recode it with the ExitLongLimit and ExitLongLimit method but without success. It would be nice to have this feature again. Thank you for lending me a hand.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by funk10101, Today, 12:02 AM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by GLFX005, Today, 03:23 AM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by nandhumca, Yesterday, 03:41 PM
                    1 response
                    12 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by The_Sec, Yesterday, 03:37 PM
                    1 response
                    11 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by vecnopus, Today, 06:15 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post vecnopus  
                    Working...
                    X