Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Enter on fixed time interval

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

    Enter on fixed time interval

    Hi,

    Say if I want to look at the bar on every 15min interval, e.g. 1001, 1016, 1031, 1101……, to see whether to enter or not. What would be the codes look like without dulplicating the following again and again?

    ToTime(Time[0]) == ToTime(10, 01, 0)

    Many thanks.
    pipal

    #2
    Originally posted by pipal View Post
    Hi,

    Say if I want to look at the bar on every 15min interval, e.g. 1001, 1016, 1031, 1101……, to see whether to enter or not. What would be the codes look like without dulplicating the following again and again?

    ToTime(Time[0]) == ToTime(10, 01, 0)

    Many thanks.
    pipal
    There are a few ways to do it. Most of the elegant methods would probably have to use the C# DateTime structures directly.

    I show one method below, with the defaults set to the values that you specified above.

    Code:
                int triggerValue = 1;
                int granularity = 15;
                
                if (Time[0].Minute % granularity == triggerValue)
                {
                    //do something
                }
    You wanted it on every minute, starting with 1, hence triggerValue = 1.
    Every 15 minutes, hence granularity = 15.

    Basically, the statement says to:

    Take the minute component of the DateTime value and divide it by 15. If the remainder is 1, then it is one minute past the minute mark that is a multiple of 15.
    Last edited by koganam; 05-14-2011, 01:17 PM.

    Comment


      #3
      Thanks so much koganam. I tried it and it works perfectly well.

      pipal
      Last edited by pipal; 05-15-2011, 03:14 AM.

      Comment


        #4
        Originally posted by pipal View Post
        Thanks so much koganam. I tried it and it works perfectly well.

        pipal
        Glad that I could help.

        Incidentally, I forgot to tell you that the code is written that way so that you can make the granularity and triggerValue into Properties. That way you can adjust them in use, without having to edit your code.

        Comment


          #5
          Originally posted by koganam View Post
          Glad that I could help.

          Incidentally, I forgot to tell you that the code is written that way so that you can make the granularity and triggerValue into Properties. That way you can adjust them in use, without having to edit your code.
          Thanks again for the bonus. I will surely have a try.

          pipal

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          666 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          377 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          110 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          580 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X