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 Mindset, 04-21-2026, 06:46 AM
        0 responses
        63 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        90 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        47 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        105 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        63 views
        0 likes
        Last Post PaulMohn  
        Working...
        X