Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TIme Filter Updating per Hour

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

    TIme Filter Updating per Hour

    Hello, I have a small script which looks like this
    Code:
    private int startTimeFilter = 070000;    //HHMMSS
    private int endTimeFilter = 120000;    
    
    //If Current Time is Greater than startTime
    if( ( !enableTimeFilter ) || ( enableTimeFilter && Time[0].DayOfWeek == startDay && (ToTime(Time[0]) >= startTimeFilter && ToTime(Time[0]) < endTimeFilter) ) )
    It works fine, but I wonder, if there's a way to make the "startTimeFilter" variable update every hour. So that at 8am it changes to 8am, at 9am it changes to 9am, etc...... Basically, I want a variable that looks like
    Code:
    private int updateTime = 60;  // 60 minute
    . How would can this be done?

    #2
    Hello ginx10k,

    Thanks for your post.

    You would want to add 10000 to go to the next hour.

    7:00 AM = 070000
    8:00 AM = 080000
    9:00 AM = 090000
    10:00 AM = 100000
    11:00 AM = 110000
    etc.

    if (some condition to update start time)
    {
    startTimeFilter = startTimeFilter + 10000;
    }


    Comment


      #3
      Thank you soo much Paul.

      Comment


        #4
        Hi Paul, I tried this
        Code:
        if( Time[0].Hour >= startTimeFilter )
        {startTimeFilter = startTimeFilter + 10000; }
        Print("Time " + ToTime(Time[0]).ToString());
        Print("Time FIlter " + startTimeFilter.ToString());
        But it's not working. How can I tell indicator to Update Time Filter every Hour??

        Comment


          #5
          Hello ginx10k,

          Thanks for your reply.

          If you print out the value of Time[0].Hour you will see that the value returned is just the hour value, ie: 0 - 23, so you are comparing the value 0 through 23 to the value of the start time filter which is initially 70000.

          Also, keep in mind that if your script runs through the night that the hour value changes at midnight back to 0.

          Comment


            #6
            Originally posted by NinjaTrader_PaulH View Post
            Hello ginx10k,

            Thanks for your reply.

            If you print out the value of Time[0].Hour you will see that the value returned is just the hour value, ie: 0 - 23, so you are comparing the value 0 through 23 to the value of the start time filter which is initially 70000.

            Also, keep in mind that if your script runs through the night that the hour value changes at midnight back to 0.
            I see what you're saying. But how would I get it update every hour? any sample script you can give me??

            Comment


              #7
              Hello ginx10k,

              Thanks for your reply.

              To trigger on an hourly basis, assuming you are using hourly bars or less:

              Try this:

              if (Time[0].Hour != Time[1].Hour) // if the time of the current bars hour is NOT equal to the previous bars hour
              {
              Print ("New hour detected"+ Time[0]); // must be new hour
              }

              Comment


                #8
                Thank you for response, I got it. it's done. Much appreciated.

                Comment

                Latest Posts

                Collapse

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