The chart shows monthly High and Low as the daily bars develop the monthly range during the month. Then on the first day of the new month, the monthly range resets to the range of the first bar, and a > in pink is shown where the month just finished closing.
Lines A and B get the month value for two adjacent bars so we can discover when the month changes to a new month by the test on Line C. So the flag in GV is True when we are on the first bar of the new month. Line D uses this flag to reset a private GV counter in  to zero. Line E increments this counter which is counting the number of bars in the current month.
Lines F and G use the counter to know how many bars back to scan for the Highest and Lowest values, which have to be the current month's high and low values. And these two lines plot the blue study lines at these max high and max low values.
Line H is just testing the flag for 1st bar of the month again and Line I is getting the close of the prior bar to put on a marker at the close value, which is where the prior month just closed. The example is sufficient to use as is, or use the concepts to do what you want.
This DYO shows a clever way to count the number of bars in the current month as the program scans across the bars in its evaluation from left to right. Then this count is used by Line F and G to harvest the values wanted from just this set of bars which are in the same month as the current bar. The way the DYO is written it would also work if applied to a 60 min chart, etc. As long as the chart has all the data for the month, it will find the high and low in that month on any time frame chart. The counter resets on the first bar of a new month. It does not matter if the data is daily, 5-minute, 60-min, or even tick, range, or volume chart..... The idea still works.
Note the bar offsets of -1 to reference the prior bar on Line A and Line I, and 0 to reference the current bar on Line B as the chart is evaluated across all bars.
This same idea would be applicable to finding High, Low and Close values on a weekly chart for use in calculating Support and Resistance levels. A DYO could harvest the weekly High and Low and Close from the chart, and use the 3 values to plot S&R lines. Combine this example with the idea in the Dynamic Fib Levels DYO example which can be found on the Help page of our web site. Then you would have Dynamic S&R levels based on prior week's HLC. Or the DYO could harvest the values wanted from a 60-minute chart.
read more » Find Weekly High and Low