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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          68 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          36 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          61 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          62 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