I have 2 questions:
Question 1:
I had a TextBox drawn in an indicator, usually that will be removed after I remove that indicator, but sometime it is not, and the TextBox will stay there forever, if I add my indicator again, the TextBox won't behave as I intended and has no effect. Wonder if there is a way to remove that object, instead of creating a new chart?
Question 2:
I have a function to handle mouse click events, the function itself works fine until I added a line to draw a horizontal line, I got an error message after I click the mouse: "Unhandled exception: "barsAgo" needed to be between 0 and 76, but was 74", I am now confused, because 74 is actually between 0 and 76? Also, the Close[0] in mouse click function is not the same as the Close[0] on the chart (the value of Close[0] in OnBarUpdate() function is always correct though)
The origin of the mouse click function was from a previous post:
https://forum.ninjatrader.com/forum/ninjatrader-8/indicator-development/96421-draw-dot-from-indicator-owner-problem?_gl=1*172zak4*_gcl_au*MTk2MDI0Mjc3NS4xNzA5 NzU3MDM1#post792624
protected void MouseClicked(object sender, MouseButtonEventArgs e)
{
// convert e.GetPosition for different dpi settings
clickPoint.X = ChartingExtensions.ConvertToHorizontalPixels(e.Get Position(ChartPanel as IInputElement).X, ChartControl.PresentationSource);
clickPoint.Y = ChartingExtensions.ConvertToVerticalPixels(e.GetPo sition(ChartPanel as IInputElement).Y, ChartControl.PresentationSource);
convertedPrice = Instrument.MasterInstrument.RoundToTickSize(chartS cale.GetValueByY((float)clickPoint.Y));
convertedTime = ChartControl.GetTimeBySlotIndex((int)ChartControl. GetSlotIndexByX((int)clickPoint.X));
Draw.Line(this, "myTag", false, CurrentBar+2, Close[0]+5 ,CurrentBar+7, Close[0]+5, Brushes.Black, DashStyleHelper.Solid, 3, true);
if (convertedPrice > Close[0])
my_value_1 = 5010;
if (convertedPrice < Close[0])
my_value_1 = 5000;
// trigger the chart invalidate so that the render loop starts even if there is no data being received
ChartControl.InvalidateVisual();
e.Handled = true;
}

Comment