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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    63 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    139 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