I modified an MACD indicator to paint the panel background in different colors based on conditions. I actually use 2 colors (buy / sell) with different opacities based on a "signal strength".
When back-testing a strategy using this indicator, I get the following error, if used on a small frequency chart (ex: 30 seconds) on a 2 weeks period:
"Brush series exceeds the maximum number (65535) of unique brushes. Please adjust code to use fewer brushes."
The visual consequence is that after a certain amount of time, the back brush color doesn't change anymore, in the Strategy Analyzer chart.
The way I change the BackBrush in the OnBarUpdate is the following:
Brush b = BuyBackgroundBrush.Clone(); b.Opacity= buySignalStrengh * OpacityFactor / 100.0; BackBrush = b; BackBrush.Freeze(); // I didn't have the Freeze until now, but it doesn't change anything.
BuySignalStrength = 1 to 4, depending on conditions.
My BuyBackgroundBrush is a property defined as
[XmlIgnore] [Display(ResourceType = typeof(Custom.Resource), Name = "Buy Signal Background Color", Order=3, GroupName = "Signal Parameters")] public Brush BuyBackgroundBrush {get; set;}
Not sure what I am missing to avoid having so many brushes used by the indicator.
Thanks for your help.
Comment