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 CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        28 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        20 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        183 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        336 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        260 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X