Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Resetting Integer Count Weekly

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

    Resetting Integer Count Weekly

    Hello,

    I have been able to reset my private integer count every session but I am looking to reset my count weekly at the end of each Friday close or at the beginning of each Sunday open. How would one go about doing so?

    I currently have:

    if (Bars.IsFirstBarOfSession && IsFirstTickOfBar)
    {
    upCount = 0;
    downCount = 0;
    }

    And this works but I have my indicator resetting around 10pm candle each night (MST) (indicator parameters considered).

    Any help would be greatly appreciated.

    Thank you.

    #2
    Hello TopGun13,

    Thanks for your post.

    To reset on a particular day of the week for your weekly reset you could use Time[0].DayOfWeek.

    if (Bars.IsFirstBarOfSession && IsFirstTickOfBar && Time[0].DayOfWeek == DayOfWeek.Sunday)
    {
    // do something once on Sunday only
    }

    Comment


      #3
      Thank you Paul for your quick reply. Sad to say, it didn't really work as it is still resetting on Sunday nights after 10pm MST. Is there a time stamp I can associate to it? If so, how would that code go?

      Thank you once again.

      Comment


        #4
        I have done this a bunch of different ways over time. The way NinjaTrader_PaulH seems as if it should work fine and I have done it this way. It could be a weird time/session template you are using?

        But here is one I have for a session break indicator I use that plots lines at the start of day, week, month, quarter, based on the template I use. Simply put, this way, is checking if a number of days have been skipped(a weekend) + the first bar of session.

        Code:
        if( (Time[0]-Time[1]).TotalDays>1 && Bars.IsFirstBarOfSession && IsFirstTickOfBar ) //Weekly Break
        {
            var myLine = Draw.VerticalLine(this, "Weekly"+CurrentBar, 0, clrWeekly, dashStyleWeekly, lineWidthWeekly);
            myLine.IgnoresUserInput = true;
        }
        Last edited by forrestang; 10-12-2021, 09:18 PM.

        Comment


          #5
          Hello TopGun13,

          Thanks for your reply.

          You may need to check your code to see if there is something else resetting or allowing to reset. You can use print statements to debug.

          I've attached an example strategy that demonstrates a weekly bar counter that is reset on Sunday. I tested on ES 12-21, default trading hours, 15-minute bars using 20 days of data. I had it draw a vertical line on the Sunday reset. I had it print the bars count bar by bar and include the time, date, and day of the week. From the print and vertical line, you can see that it performs as expected.

          Click image for larger version

Name:	Resetweeklyexample.PNG
Views:	307
Size:	103.2 KB
ID:	1174677

          [ATTACH]n1174678[/ATTACH]

          Comment


            #6
            Thank you Paul and forrestang.

            Found the error in my code and it's working. This is excellent. Thank you once again.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            597 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            343 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
            556 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            555 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X