Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Specify a bar time without specifying timeframe

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

    Specify a bar time without specifying timeframe

    Hello,

    When trying to create a Time condition, how do you make this non-timeframe dependent as in it will pull the correct bars end time (bar time) regardless of timeframe?

    For example:
    Code:
    if (ToTime(Time[0]) == 093000 + (BarsPeriod.Value * 100))
    {
    MyPrice = Open[0];
    }
    The above would grab the open price of said bar that matches the time condition. However, this only work for timeframes <= 59min since 24hr time is used. How could I create the same condition above, but have it be generic across all timeframes?​

    #2
    Hi ChrisR, thanks for posting. You will need to use the DateTime.AddMinutes() method:

    Returns a new DateTime that adds the specified number of minutes to the value of this instance.


    You will need to use a DateTime object instead of the 093000 integer and also use DateTime.Compare to compare the Time[0] DateTime with your own custom DateTime:

    string timeString = "093000";
    DateTime dateTime = DateTime.ParseExact(timeString, "HHmmss", CultureInfo.InvariantCulture);

    Comment


      #3
      Time[0].Date.AddHours(9).AddMinutes(30 + BarsPeriod.Value)
      Bruce DeVault
      QuantKey Trading Vendor Services
      NinjaTrader Ecosystem Vendor - QuantKey

      Comment


        #4
        Thanks both of you, got it situated. Looking back it was rather obvious to just use DateTime.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        608 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        355 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        560 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        561 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X