Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issues with stop orders being ignored in backtesting.

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

    Issues with stop orders being ignored in backtesting.

    1. I'm having some difficulty with this. I'm currently utilizing the "On Bar Close" protocol for the automation, and it seems to me that it would not be possible to use the entry bar low or high as the stop price with this functionality. But, is there a way? And if so, does anyone know how?



    2. The second challenge I am having is that during backtesting, the price passes through a presumed stop order as if it didn't exist. There are multiple instances of this in the results of backtesting, so it is difficult to try and determine what the cause is. Below is an example.




    Click image for larger version

Name:	image.png
Views:	99
Size:	9.6 KB
ID:	1330046

    What I would like the stop order to do is be at the high of the entry bar. But what I believe my current strategy to be able to accomplish is the high of the signal bar (one bar previous), but even this is being ignored.

    I am only using the NT8 strategy builder, and am not very proficient in scripts or coding, so I'm at a bit of a loss here on how to debug what is going on.

    There are instances where the behavior is as expected, but it isn't consistent.

    What's the best way to work through this? I'm in uncharted waters and definitely need some help. Happy to provide any chunks/all of the code for debugging as well.

    Thanks​

    #2
    Hello sclay115,

    To use the entry bar prices you would need to use the intrabar logic with tick replay and the appropriate orders that take a price. From there when the fill engine evaluates the fill it will fill the order.

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello sclay115,

      To use the entry bar prices you would need to use the intrabar logic with tick replay and the appropriate orders that take a price. From there when the fill engine evaluates the fill it will fill the order.
      Thanks Jesse

      You're referencing backtesting specifically, correct? In a forward looking live environment, will the prices fill on the entry bar? Right now, this is the order management section of my order entry set looks like, could you check my logic here and tell me the result of these actions?

      Click image for larger version  Name:	image.png Views:	0 Size:	2.8 KB ID:	1330055

      Here is what I think would happen (please definitely correct me).

      Click image for larger version

Name:	image.png
Views:	83
Size:	10.7 KB
ID:	1330056

      Since I am using "on bar close":

      There will be a short entry limit order placed at the low-1 tick of the signal bar (blue line)
      There will be a short exit stop order placed at the high of the signal bar (red line)

      Is that correct so far?

      Comment


        #4
        Hello sclay115,

        Yes in a real time test the orders would be submitted at the intrabar price assuming you are using Calculate OnPriceChange or OnEachTick. If you are using OnBarClose that would work like a backtest and wait for the close of the bar to submit the order.

        Comment


          #5
          Thanks Jesse, that makes sense.

          So my next question is, if I am using on bar close, and the order is submitted as shown on the screenshot, why is the stop loss not set at the high (blue line) of the previous bar? Is there something I'm missing or not understanding?

          Comment


            #6
            Hello sclay115,

            From the image I can't tell where the orders were placed as they are not in the image. You can use a Print statement to print the time and prices that are used when the order is submitted.

            Comment


              #7
              Let me ask something else to see if I can get to the answer I need on my own.

              When the strategy is using "on bar close", and you give the command to look back X number of bars, which bar is it going to look at? Does it look back X number of bars from the entry? Or X number of bars from the signal?

              Click image for larger version

Name:	image.png
Views:	76
Size:	10.0 KB
ID:	1330190

              Using the image above as an example, considering that the bar where it entered short is the entry bar (bar zero?), if I were to use this command package:

              Click image for larger version

Name:	image.png
Views:	76
Size:	3.5 KB
ID:	1330191

              ​What should the order entries look like?

              Comment


                #8
                Hello sclay115,

                BarsAgo directly relates to the bar that's processing, 0 bars ago is the current bar that is closed when using OnBarClose processing, 1 would be the bar prior to that.

                Regarding the image I couldn't say what the prices or placement would be based solely on the image, you need to use a Print to see when the condition was true, print out the bar time along with the prices you submitted the orders at. That will tell you the specific bar where the entry was true and what prices were used with the order.

                Comment


                  #9
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello sclay115,

                  BarsAgo directly relates to the bar that's processing, 0 bars ago is the current bar that is closed when using OnBarClose processing, 1 would be the bar prior to that.

                  Regarding the image I couldn't say what the prices or placement would be based solely on the image, you need to use a Print to see when the condition was true, print out the bar time along with the prices you submitted the orders at. That will tell you the specific bar where the entry was true and what prices were used with the order.
                  Thanks Jesse, that's helpful.

                  This strategy is using a simple "cross above" or "cross below" behavior as part of it's script.

                  When using onbarclose, how is this cross behavior handled? I know there is a "look back period" available for this function available, so I'm curious how it works.

                  I theorize that once a correlating condition is met, e.g. Open < Close, 0 bars ago, that it then checks to see if the cross below or cross above qualifier has been also met X bars ago? Where X is the "look back period"?

                  Comment


                    #10
                    Hello sclay115,

                    OnBarClose means your logic in OnBarUpdate is executed once per bar when the bar is processed. Cross behavior would use the closed bar and the previous bar to check if the price crossed. The lookback period looks for more than just the current and previous bar.

                    Comment


                      #11
                      Originally posted by NinjaTrader_Jesse View Post
                      Hello sclay115,

                      OnBarClose means your logic in OnBarUpdate is executed once per bar when the bar is processed. Cross behavior would use the closed bar and the previous bar to check if the price crossed. The lookback period looks for more than just the current and previous bar.
                      Thanks! This is all very helpful.

                      Can you help me understand what you mean by OnBarUpdate? Is this different than OnBarClose? I've not seen this wording specifically anywhere so I'd like to understand more thoroughly what you mean.



                      And so I can be sure I understand what you mean, please check my knowledge here (excuse the crude annotations):

                      Click image for larger version

Name:	image.png
Views:	85
Size:	13.2 KB
ID:	1330285

                      Assuming an indicator crossing is part of my logic, here is what I think should happen;

                      Bar 2 closes, the logic checks to see if the indicator cross has occurred within the past X bars (X being the look back period), if so, it also checks to see if all other conditions are met. In this case, we'll assume that the indicator has not crossed within the previous X bars, so it takes no action even if the other qualifiers have been met.

                      Bar 1 closes, and the logic sees two things:
                      1. The indicator cross has occurred within the past X bars
                      2. Bar 1 closes and meets all other qualifiers and takes the actions in the set of instructions in the strategy
                      In this case, here is what I assume should happen immediately upon the close of bar 1, given the instructions of:

                      Click image for larger version

Name:	image.png
Views:	74
Size:	3.6 KB
ID:	1330286
                      1. There is a short entry order placed 1 tick below the Low of Bar 1
                      2. There is a short stop market order placed exactly at the High of Bar 1
                      How did I do? Does this match what should have happened? I think I'm getting closer to seeing what the problem may be with my strategy, and again, I really appreciate the help!

                      Comment


                        #12
                        Hello sclay115,

                        OnBarUpdate is where your code is inside your script, that is how its executed.



                        In your image is the condition happens on bar 1 the execution will be shown on the next bar depending on the prices used and if that would fill within the next bar.


                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by NullPointStrategies, Today, 05:17 AM
                        0 responses
                        41 views
                        0 likes
                        Last Post NullPointStrategies  
                        Started by argusthome, 03-08-2026, 10:06 AM
                        0 responses
                        124 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        64 views
                        0 likes
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        41 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Started by TheRealMorford, 03-05-2026, 06:15 PM
                        0 responses
                        46 views
                        0 likes
                        Last Post TheRealMorford  
                        Working...
                        X