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, 03-31-2026, 09:41 PM
        1 response
        72 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        39 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        63 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        63 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X