My sincerest apologies, I did not explain the idea well. The idea is that the indicator draws the maximum and minimum of each week and month, and the lines are extended to the present.
For example n = 10 then calculate and draw the maximum and minimum for week 1 and extend to the present, then for week 2 and then 3 and so on until 10.
Thank you very much for your great work.
I attach an image