Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy closes after one bar in backtest.

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

    Strategy closes after one bar in backtest.

    Hello,

    My script uses action based entries, (i.e. if current bid/ask > Benchmark+4ticks ; Enter long) and uses the same process for stop loss orders. (Benchmark //Open price of the 8:30AM 30minute bar)

    The problem I am experiencing is during a back-test, the strategy will exit its current position and will cease to place new orders when the current bar closes. it needs to continue its position through the day always referencing the Benchmark price until it reaches its profit target or stop loss

    I run the same exact script in a playback simulation and it preforms correctly. The only difference I made to adjust the script from a back-test version to a play-back version was to disable State == State.Historical and make IncludeTradeHistoryInBacktest = false.

    #2
    Hi Don22, thanks for writing in. Is the strategy mixing SetStopLoss and Exit orders together? If so this is likely a case of historical overfill where both the stop losses fill on the same bar and it exceeds the entries per direction. You can see if this is the case by turning on TraceOrders in your strategy and looking at the output window when the strategy runs on the historical data. Do not mix Set methods and Exit methods for your stop loss, or try turning on High order fill resolution (High>1 Tick) to improve the order fill accuracy.

    Kind regards,
    -ChrisL

    Comment


      #3
      Thanks for the reply ChrisL,

      The strategy does not contain SetStopLoss Orders, only Exit methods so I don't see where the two can mix and I cannot use High order fill resolution because I have enabled Tick Replay for my backtests.

      Comment


        #4
        Hi Don, the overfill issue is going to be specific to the code you have written. Our colleague Jim has a guide here on how you can discover what part of your strategy is causing the overfill:



        Kind regards,
        -ChrisL

        Comment


          #5
          Afternoon ChrisL,

          Thanks for your patience; however, I still have not found a solution for my problem.

          I have read the link for Jim's post on overfill and I have not concluded that this may be the problem. Can an overfill happen without receiving an error about it? Because I have not received a message nor has it been noted on trace orders log in the output window.

          Comment


            #6
            Hi Don, thanks for the follow up.

            An overfill can happen without a direct error message about it. E.g. you can get an error in the trace about the strategy violating the EntriesPerDirection setting, and that can be from two stop orders filling on the same bar. Make sure you have turned on the Trace Order in your strategy to get information like this.

            Kind regards,
            -ChrisL

            Comment


              #7
              Hey ChrisL,

              Below I have attached 5 Pictures. The first three pictures show what happens when no Set Methods are used, only ExitLong & ExitShort Methods. The next two pictures have Set Order Methods for their profit and loss.

              When I use only Exit Methods, the strategy performs how it should on the first bar but will not keep its position open when the next bar appears. Also, by observing the trace orders I see that the position does not close exactly when the next bar opens. In this case it closed 19 Minutes and 56 Seconds later within the next bar one tick below the open of the 9:30 Bar. I have attached a picture of the final trade in the output window with custom prints and trace order turned on so you may see if overfill may be the problem here.

              When the Set Order Methods are used, The position will hold like it should throughout the day, but now a ridiculous amount of trades were taken, in this case around 4782 trades. This day should have taken at most around 12 trades so I know this is not accurate.

              Here is some additional information of the parameters of my strategy that may provide some help.
              Calculate = Calculate.OnPriceChange
              Primary Data Series is the 30 minute Bar but the strategy enters using a 1 Tick Series for intrabar granularity.


              Click image for larger version

Name:	Z011ChoppyBacktest.jpg
Views:	325
Size:	117.5 KB
ID:	1197723Click image for larger version

Name:	Z011ChoppyBacktest Entry&Exit Logic.png
Views:	283
Size:	106.1 KB
ID:	1197724Click image for larger version

Name:	Z011ChoppyBacktest Trace Orders.png
Views:	276
Size:	103.4 KB
ID:	1197725 ********************** Click image for larger version

Name:	Z011ChoppyBacktestOrderMethods.png
Views:	282
Size:	77.7 KB
ID:	1197726Click image for larger version

Name:	Z011ChoppyBacktestOrderMEthoda Entry&Exit Logic.png
Views:	310
Size:	28.7 KB
ID:	1197727


              I appreciate your Help.

              Comment


                #8
                Hi Don, I am seeing that not all Exit orders are using BarsInProgress=1 to submit the order to a 1 tick series: ExitLong("LSEntry"); this one should also use the 1 tick series. If the strategy is not holding is position, what exit order is being fulfilled to exit the position? With the Set methods, these should be called before the entry order to ensure the correct stop and target prices are set before the entry occurs.

                Comment


                  #9
                  ChrisL,

                  The issue has been resolved. When I included the correct BarsInProgress of "1" in the ExitLong Syntax, it held its position throughout the day.

                  Thanks for your help.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  62 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  134 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  75 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  45 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  50 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X