Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

bar counter problem

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

    bar counter problem

    Hi,
    I developed a little bar counter in the builder. It counts the bars from the beginning of the session until the end of the session. For example in the RTH futures, it counts the first bar of the session as "1" and continues until "90" when the session ends, and restarts each session. The problem is that only on the very first day in the series, the first bar is a null and the second bar is a 1 and so on. The first bar on the first day in the backtest always gets skipped. How can I remedy that?
    thanks,
    David

    Attached Files

    #2
    Hello trader3000a,

    Thanks for your post.

    This would be the expected behavior when running the script with Calculate.OnBarClose. The script will only process logic at the close of a bar so when bar 1 closes and bar 2 begins to form, you will see the bar counter increment to 1.

    Something you could consider doing is running the strategy with Calculate.OnEachTick and creating a condition that checks if IsFirstTickOfBar (Misc folder > IsFirstTickOfBar) is True (Misc folder > True) in your condition to increment the bar counter. This would mean the strategy would check if the current tick is the first tick of a bar and increments the bar counter by 1.

    See this help guide page for more information about Calculate: https://ninjatrader.com/support/help.../calculate.htm

    See this help guide page for more information about IsFirstTickOfBar: https://ninjatrader.com/support/help...=isfirsttickof

    Let me know if I may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    90 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    137 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    120 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    71 views
    0 likes
    Last Post PaulMohn  
    Working...
    X