Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Last bar of Strategy Analyzer is not accessible

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

    Last bar of Strategy Analyzer is not accessible

    Hi,

    When running a strategy in Strategy Analyzer, if I have an order active before the end of session of the last date, and IsExitOnSessionCloseStrategy is set to true, processing the last bar of the last date (the bar before the session end of the End date):
    1. The bar is shown on the chart - Correctly
    2. Order is closed using "Exit on session close" - Correctly
    3. But, the OnBarUpdate doesn't get this last bar and the strategy stops one bar before - Missing, possibly a a bug
    I believe this may be a bug.

    #2
    Hello Shai Samuel,

    That would be correct because there is not another bar following that bar. The last bar on the chart would only be able to have exit on session close if you have that enabled, logic wouldn't be expected to be run on the last bar because nothing more can be done in the test at that point in time.

    Comment


      #3
      Thank you Jesse for your quick reply. Even with Calculate = Calculate.OnBarClose, I find it hard to understand why the last bar is never handled during OnBarUpdate(). This a valid bar, and is process with everything else except the Strategy. In my eyes, it is a BUG and not a feature.

      Comment


        #4
        Hello Shai Samuel,

        Backtests only work using OnBarClose, in realtime you can use the building bar of the chart.

        There is no additional data to continue processing past that point in a backtest which is why you get that result. If we make the assumption that bar was used to call OnBarUpdate and your conditions to enter or exit were true, what happens at that point? There is no next bar to process the logic and the order would not be seen directly on that bar because there is no intrabar granularity to continue processing. You won't be able to do any action on that last bar which would contribute to the results of the test. This is why you see your logic stop working 1 bar before the end so that the final result can be calculated.

        The analyzer has specific logic for exit on session close which will show the fill on the very last bar of the chart rather than the session close which is why you see that happening at the end. That is so you have that last trade included in the results. In historical the exit on session close is otherwise always placed on the final bar of the session disregarding the number of seconds specified.

        Comment


          #5
          Thank you Jesse, I understand the point you are making. So here is my question, I use the OnBarUpdate not only to initiate order and handle them, but also to log the PNL using SystemPerformance.AllTrades.FirstOrDefault. Since the trade is exited on this last bar due to session close, the Trade.Exit record is suppose to be initiate during this bar, but I have no way to access it. Any suggestion?

          Comment


            #6
            Hello Shai Samuel,

            You can use OnExecutionUpdate for that purpose and print your data from that override. That is called for each execution that the strategy tracks.

            Comment


              #7
              Thank you Jesse. I ended up using OnStateChange State.Terminated to do the last call to the last bar.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Today, 05:17 AM
              0 responses
              44 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              125 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              65 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              42 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