This seems a strange problem, for me at least.
I've used the drawingtools_drawobjects from the helpguide and an old article LINK
The debug print output shows many found objects:
Found: Line with tag: Line 8891Userdrawn is True
Found: Line with tag: Line 8892Userdrawn is True
Found: Line with tag: Line 8893Userdrawn is True
Found: Rectangle with tag: Rectangle 2567Userdrawn is True
Found: Rectangle with tag: Rectangle 2568Userdrawn is True
Found: Rectangle with tag: Rectangle 2569Userdrawn is True
But the condition is never true and it never passes any of the statements I tried: if (draw is DrawingTools.Rectangle)
What am I doing wrong? (Ultimately I want to call playsound when price touches a rectangle in realtime )
2nd question, how to make this faster so it doesnt go through every single drawing object, this DrawObjects.ToList() seems very slow if only looking for rectangles?
//Print("in onbarupdate"); //if (State != State.Realtime) return; // waits until real time connected then finds rectangle (only did for this test) Print("realtime in onbarupdate"); if (DrawObjects.Count > 0) // Make sure we have an objects first { Print("count is more than zero"); foreach (DrawingTool draw in DrawObjects.ToList()) // Go through objects { // Retrieve the type of the current object Type objectType = draw.GetType(); // Print the type of the object found Print("Found: " + objectType.Name + " with tag: " + draw.Tag + "Userdrawn is " + draw.IsUserDrawn); if (objectType.Equals(typeof(DrawingTools.Rectangle)) && draw.IsUserDrawn) { Print("found rectangle"); DrawingTools.Rectangle rectangle = draw as DrawingTools.Rectangle; // Get the tag of the rectangle string rectangleTag = rectangle.Tag; // Get the anchor points of the rectangle double upperPrice = rectangle.StartAnchor.Price; double lowerPrice = rectangle.EndAnchor.Price; // Print the type, tag, upper price, and lower price of the manually drawn rectangle Print("Object Type: " + objectType.Name + ", Rectangle Tag: " + rectangleTag + ", Upper Price: " + upperPrice + ", Lower Price: " + lowerPrice); } if (draw is DrawingTools.Rectangle) // test to find rectangle { Print("found rectangle"); Print ("Tag name: "+draw.Tag); // priint tag name DrawingTools.Rectangle temp = draw as DrawingTools.Rectangle; // create copy to get anchorpoints Print("startY: " + temp.StartAnchor.Price); Print("startX: " + temp.StartAnchor.Time); Print("endY: " + temp.EndAnchor.Price); Print("endX: " + temp.EndAnchor.Time); } } }
Comment