Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Transition from Historical to Live - StopLoss Triggers at Close of Bar

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

    Strategy Transition from Historical to Live - StopLoss Triggers at Close of Bar

    Situation:
    Strategy not exiting position at price expected if a strategy is "transitioning" from historical to live data.

    Description:
    Prior to the current bar, the stoploss fills as expected, immediately and anywhere within a bar

    Click image for larger version

Name:	Waiting to go flat.jpg
Views:	1
Size:	69.7 KB
ID:	897335When the strategy is on the current bar, and waiting to "go flat", the stoploss, when "hit", doesn't fill until the open of the next bar.

    Click image for larger version

Name:	seconds later after strat reload.jpg
Views:	1
Size:	72.3 KB
ID:	897336The stoploss is filled as expected if either the data or the script are reloaded



    Additional Information:
    • Using 8 tick stop
    • CalculateOnBarClose = True
    • Strategy has a historical position waiting to close
    • Strategy Option "Wait until Flat Before Executiing Live

    #2
    dojidubbs

    Thank you for your post.

    Can you clarify what you mean by strategy transitioning from historical to live? Are you saying that the strategy does not behave as expected on the real-time/live data? Or are you having issues historically?
    MatthewNinjaTrader Product Management

    Comment


      #3
      "Transitioning" as I defined it is when you are processing real time ticks, yet the strategy is waiting to go flat. Not sure if there is a better term, but its when you are getting real time data, but the Historical flag is true due to waiting for the strategy to go flat.

      Historically in time, the trades execute as expected (first trade in the as in the first picture). So no issues in time historically.


      When in the "transition", that is the second trade in the first pic (historical flag true, but processing realtime ticks, due to the strategy waiting to go flat)

      As you can see, first trade stopped out at 2pts, second trade stopped out at 3 pts, 1 point farther than expected (with a 2pt stop).

      Subsequent trades, after the strategy goes flat and green, also execute properly.

      Hope that clarifies.

      Comment


        #4
        Doji,

        Thanks for the clarification however I'm unable to replicate.

        Can you replicate this using one of the sample strategies such as the SampleMACrossOvers strategy?

        If so, can you please detail the exact steps it takes to reproduce this issue?

        Thanks in advanced
        MatthewNinjaTrader Product Management

        Comment


          #5
          None of the sample strategies I have include stoploss, so I have attached a simple strategy I created with the wizard, go long, 8 tick target, 8 tick stop.


          Steps to replicate:
          • Connect to Simulated Data Feed
          • Open a 1 min ES 09-11 chart
          • Add attached strategy to chart
          • Enable Strategy via the control center strategies tab
          • Ensure strategy is in a position, waiting to go flat
          • Slide trend slider all the way down
          Attached Files
          Last edited by dojidubbs; 09-05-2011, 12:15 PM. Reason: Clicked enter too early

          Comment


            #6
            dojidubbs,

            Thanks for the details.

            This would be expected if you are using CalulateOnBarClose = true. The exit order would not be submitted until the end of the bar. If you set this to false, you should see the stop loss triggered when 8 ticks have been reached.
            MatthewNinjaTrader Product Management

            Comment


              #7
              I don't see how this is "expected" behaviour.

              A stop order is submitted as soon a fill happens.

              So looking at the first picture, bar 61 has a fill of 1039.25. There is a working stop order working on bar 62. I can see it when I do a trace order, there is a stop order for 1037.25 when bar 62 opens. It just doesn't trigger.

              Looking again at the same picture, you can see for the trade to the left, the stop triggers mid bar at 1039.50. Stops don't wait for the bar to end to trigger. If I show trades after the strategy goes flat and is green, they work as expected.

              This situation only happens if the strategy has an open position and is waiting to go flat.

              I don't understand "It is by design that stop losses will not trigger properly if a strategy is waiting to go flat, but any other time they will work properly".

              Comment


                #8
                You are correct in a live environment, however that is not true when working off of historical data.

                What I said above would only apply when running on historical data. Regardless if you're dealing with entry methods, exit methods or stops/targets methods, they can only wait until the close of the bar to be filled in your scenario.
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Sorry, I am still missing it. The first trade in the first picture is on historical data. It shows an exit properly, at the stop desired, and doesn't wait until the bar closes.

                  What am I missing here?

                  Comment


                    #10
                    dojidubbs,

                    Just wanted to let you know that were are double checking with development on this item. You should get an answer shortly.
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      Thank you very much Matthew, the update is very much appreciated.

                      Comment


                        #12
                        Any progress on an answer for this item?

                        Comment


                          #13
                          Hello,

                          This is expected in this case with COBC = true.

                          Here is what happens.

                          In historical and simulated live we process OnExecution() after OnBarUpdate().

                          Since OnBarUpdate() doesn't trigger until the bar closes OnExecution() does not trigger until the bar closes. Which gives you the stop loss value at the end of the bar.

                          The difference between pure historical mode where we will go in and modify the price to be the stop price + slippage set so the order appears in the middle of the bar where you would have been stopped out. We do not do this in simulated live mode while you wait for the strategy to go live as we dont make adjustments on live anything. Its simply posts as shown and is a limitation of waiting to go live with the display of where the stop loss price is executed.

                          The strategy will still transition to live correctly as expected however.

                          Let me know if I can be of further assistance.
                          BrettNinjaTrader Product Management

                          Comment


                            #14
                            Thank for the response, especially the "why it happens" part.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            672 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            379 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            111 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            575 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            582 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X