I cannot iterate through DrawObjects because it always seems to equal zero or is empty.
I CAN delete a specific historically drawn object if I know its exact tag but I'm trying to mass delete objects if their tag CONTAINS a string.
To illustrate the problem simply, please do the following:
1. Create a new strategy and immediately press 'Generate.'
2. Copy the below code into it and save and compile.
3. Open Strategy Analyzer based on that new strategy with the following parameter:
- Instrument: MES 06-23 (Though I don't think this matters)
- Price based on: Last
- Type: Volume
- Value 200
- Start and End date: 05/19/2023
- Everything else is default value
5. Press 'Run'
6. Change the Strategy Analyzer display from SUMMARY to CHART and scroll the chart to the far left to see the drawn objects.
Does it look similar to my screenshot? No functioning drawobject.count and all the diamonds remain except for the one successfully removed "DIA_Diamond 10"?
I hope you have the same results as I do. If so, what's going on? If not...what am I doing wrong?
How can I delete historically drawn objects when their tag contains a certain string?
public void DeleteAllFromChartByTagContains(string text)
{
List<DrawingTool> itemsToRemove = new List<DrawingTool>();
foreach (DrawingTool dt in DrawObjects.ToList())
{
if (dt.Tag.Contains(text))
{
itemsToRemove.Add(dt);
}
}
foreach (DrawingTool dt in itemsToRemove)
{
RemoveDrawObject(dt.Tag);
}
}
string diamondPrefix = "DIA_";
protected override void OnBarUpdate()
{
if(CurrentBar < 20)
{
Draw.Diamond(this, diamondPrefix + "Diamond " + CurrentBar, true, 0, High[0] + .5, Brushes.Red);
Draw.ArrowUp(this, "Arrow " + CurrentBar, true, Time[0], High[0] + 1, Brushes.White);
Print("Number of DrawObjects: " + DrawObjects.Count);
}
if (CurrentBar == 21)
{
RemoveDrawObject("DIA_Diamond 10");
DeleteAllFromChartByTagContains(diamondPrefix);
Print("Number of DrawObjects: " + DrawObjects.Count);
}
}

Comment