Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculation using Time[0] not working for a tick chart in Tick replay mode

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

    Calculation using Time[0] not working for a tick chart in Tick replay mode

    Hi - I am trying to program a very simple indicator that gives me the time elapsed between two bars in a tick chart. This is because the time taken to form a bar in the tick chart will be different during high activity times (like opening and closing bell) and low activity times (during the afternoon or outside regular trading hours).

    I have attached the script and the results. When tick replay is OFF then the indicator works fine and plots appear. Please see image 1 for the same. However, when tick replay is ON then the indicator doesn't give any output. Please see image 2 for the same.

    Can you please help me make the necessary changes to make this script work in a tick chart with tick replay ON?
    Attached Files

    #2
    Hello samanruptrader,

    Thanks for your post.

    When testing your script on my end I am seeing an error occur in the Log tab of the Control Center.

    The error in the Log tab states: Indicator 'TickchartSpeed': Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    You would need to add a CurrentBar check to your script to make sure you have enough bars on the chart that you are accessing.

    For example, at the top of OnBarUpdate() add the code:

    if (CurrentBar < 2)
    return;


    //rest of your code below

    This would check to see if at least two bars have formed on the chart before the script processes logic. After adding this code to the script, I see the script working with Tick Replay off and with Tick Replay on.

    See the help guide documentation below for more information.

    CurrentBar - https://ninjatrader.com/support/help...currentbar.htm
    CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
    Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm
    <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


      #3
      Thank you for the quick response.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      579 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X