Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple Time Question

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

    Simple Time Question

    Hi,

    I'm using a secondary data series to get a 15 minute series.

    I want to calculate if more than 10 minutes is up on the current bar (which I'm calculating OnPriceChange).

    What I want is, if the dynamic current chart time is more than 10 minutes of the close of the previous bar, do x.

    Thank you!!

    #2
    Hello davydhnz,

    Thanks for your post.

    You could consider using the AddDataSeries() method to add a secondary 10-minute data series to your script to use for your calculations.

    For example, you could add a 10-minute secondary data series to the script and if this is the first added series then the script then you could create a condition that checks if IsFirstTickOfBar is true in BarsInProgress == 1.

    This would check if the first tick of a new bar is processing which indicates the close of the previous 10 minute bar, meaning 10 minutes have passed.

    Code:
    if (BarsInProgress == 1)
    {
        if (IsFirstTickOfBar)
        {
            //do something.
        }
    }​
    See the help guide documentation below for more information.

    AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
    BarsInProgress: https://ninjatrader.com/support/help...ess.htm​
    IsFirstTickOfBar: https://ninjatrader.com/support/help...ttickofbar.htm
    Working with Multi-Timeframe/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.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
      Hi NinjaTrader_BrandonH ,

      I appreciate the reply, but the indicator is already on a 5 minute chart.
      So the 15 minute calculations are the first secondary data series.

      Any idea what to do in such a situation?

      I was hoping I could go, if current datetime is > previous bar close datetime Time[1].AddMinutes[10],
      but I'm not exactly sure how to do it.

      Thank you!

      Comment


        #4
        Hello davydhnz,

        Thanks for your notes.

        If the primary series is a 5-minute data series then checking if Time[0] > Time[1].AddMinutes(10) would likely not become true since the current time (Time[0]) will only ever be 5 minutes greater than the previous bar time (Time[1]) since these are 5-minute bars.

        You could consider creating a condition that checks if Time[0] >= Time[2].AddMinutes(10) which would evaluate as true since the Time[0] of the current bar would be equal to the Time[2] of the bar 2 bars ago (2 bars passed so this means 10 minutes passed).

        Here is a reference sample you could view about manipulating DateTime objects which you might find helpful: https://ninjatrader.com/support/help...me_objects.htm

        Otherwise, you could add a 10-minute secondary series to the script and use the secondary series to calculate logic as noted in post # 2. Or you could create a condition that checks if the current bar time of the added series (Times[2][0] if its the second added series) is greater than the previous bar time of the added series (Times[2][1]).

        Times: https://ninjatrader.com/support/help...ries_times.htm


        Last edited by NinjaTrader_BrandonH; 10-16-2023, 07:55 AM.
        <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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        574 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X