Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get optimization trade Bars from Results

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

    How to get optimization trade Bars from Results

    After running an optimization, the trades list shows a column reporting the number of Bars per trade


    Click image for larger version

Name:	Capture.png
Views:	75
Size:	77.5 KB
ID:	1284369
    On the Optimizer code, the property Results keeps a SystemPerformance array where pretty much all the information is available. However, I wasn't able to find the Bars duration for trades. Either I am missing the correct property in the Trade class, or that value is calculated by some other property that I can't figure out.

    How can this be done?
    franco.tiveron
    NinjaTrader Ecosystem Vendor - franco.tiveron

    #2
    Hello franco.tiveron,

    That is not a value that is contained in the trade performance and is just part of the results view. To find that value you would need to calculate the number of bars between two trades by using the execution times. You would use the entry time to find a bar index using GetBar() and do the same for the exit execution, then find the difference between the two values.

    Comment


      #3
      I tried that but unfortunately at the end of an optimization, Strategies[0].Bars is null. What is the most convenient way to retrieve bars at the end of an optimization? Being the code in an AddOn, should I rely on BarsRequest, or is there a better way starting from the optimizer?
      franco.tiveron
      NinjaTrader Ecosystem Vendor - franco.tiveron

      Comment


        #4
        Hello franco.tiveron,

        That would be something you would need to calculate as the script processes, there is no concept of doing processing after the test has ended. After the test ends the properties that can be released are released.

        In regard to an addon, there is no support for using the trade performance or backtesting for addons so I could not suggest anything for that type.

        Comment


          #5
          Never mind, I got what I needed using BarsRequest.
          franco.tiveron
          NinjaTrader Ecosystem Vendor - franco.tiveron

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          88 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          48 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          30 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          34 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          68 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X