If you have lot of draw objects, this has indeed a negative impact on performance and the loading of the chart may take quite a long time. This does not only affect rectangles, but also applies to arrows, diamonds and other draw objects.
What I have done for some of my indicators, is that I entered a user-selectable lookback period, for example 15 days from now. I then check for that lookback period in OnBarUpdate and only plot those rectangle if the barTime is inside that lookback period.
This speeds up the indicator, as the rectangles are not plotted over the whole lookback period of the chart.
Another way of doing it - maybe more elegant:
-> Check ChartControl for null in OnStartUp (to avoid problems if your indicator is addressed by another indicator or strategy)
-> Determine the last bar painted on your current chart.
-> Plot rectangles only, if they are within a lookback period of 15 something days counted from the last bar painted.
The following user says Thank You to Fat Tails for this post: