I want to get the Bar value of where mouse is clicked and have to draw some line using Bars High and Low from my Indicator. I have written below to code to access the Hing and Low. But It is not working and throwing some exception. I need your help to fix this.
CODE :
protected override void OnStateChange()
{[INDENT]if (State == State.Configure)
{
}else if (State == State.Historical)
{
}else if (State == State.DataLoaded)
{
ChartControl.ChartPanels[0].MouseDown += MouseClicked;
}
else if (State == State.Terminated)
{
ChartControl.ChartPanels[0].MouseDown -= MouseClicked;
}[/INDENT]
}
protected void MouseClicked(object sender, MouseButtonEventArgs e)
{
try{[INDENT]DateTime slotTimeX = ChartControl.GetTimeByX((int)ChartControl.MouseDow nPoint.X);
int barsAgo = CurrentBar - Bars.GetBar(slotTimeX);
Print(barsAgo);
Print (High[barsAgo]);
Print (Low[barsAgo]);[/INDENT]
}catch(Exception exc)
{[INDENT]Print(exc);[/INDENT]
}
//Print((e.MiddleButton == MouseButtonState.Pressed).ToString());
}
Exception :
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)
at NinjaTrader.Data.BarsSeries.GetClose(Int32 index)
at NinjaTrader.Data.Bars.GetClose(Int32 index)
at NinjaTrader.NinjaScript.PriceSeries.get_Item(Int32 barsAgo)
at NinjaTrader.NinjaScript.Indicators.SolzzSnRIndicat or.MouseClicked(Object sender, MouseButtonEventArgs e)

Comment