I am trying to add Text and ellipse on chart calling from within OnExecutionUpdateAccount but neither text nor ellipse shows up on the chart. I have tried both Dispatcher.InvokeAsync and direct call (which I knew is incorrect but still tried for completeness). Here is the code snippets. Appreciate any pointer.
//Dispatcher call
private void OnExecutionUpdateAccount(object sender, ExecutionEventArgs e)
{
if (e.Execution.IsEntry)
{
Print("Order executed - Entry detected"); // Debugging
Dispatcher.InvokeAsync(() =>
{
Print("Drawing on UI thread"); // Debugging
// Use execution price for positioning
double entryPrice = e.Execution.Price;
// Draw ellipse and text
Draw.Ellipse(this, "entryEllipse_" + CurrentBar, true, 0, entryPrice, 10, 10, Brushes.Red, Brushes.Red, 5, true);
Draw.Text(this, "entryText_" + CurrentBar, "Entry", 0, entryPrice, Brushes.White, null, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0, true);
});
}
ForceRefresh();
}
//Direct call
private void OnExecutionUpdateAccount(object sender, ExecutionEventArgs e)
{
if (e.Execution.IsEntry)
{
// Draw the ellipse
Draw.Ellipse(this, "entry1", true, 1, Close[0], 0, Close[0], Brushes.Red, Brushes.Red, 5);
// Add text to the chart
Draw.Text(this, "entryText1", "Entry", 1, Close[0], Brushes.White);
ForceRefresh();
}
}

Comment