I am confused because I am trying to access Open price and I can see the Open Count is 3. Bar Id clicked is 1. My code is Open[Open.Count - barId - 1] which should be in range.
Cound you please help to explain or point to some resources?
My code:
protected void MouseLeftClicked(object sender, MouseButtonEventArgs e)
{
if (!active)
return;
try
{
var y = ChartingExtensions.ConvertToVerticalPixels(e.GetPo sition(ChartPanel as IInputElement).Y, ChartControl.PresentationSource);
var x = ChartingExtensions.ConvertToHorizontalPixels(e.Get Position(ChartPanel as IInputElement).X, ChartControl.PresentationSource);
var priceClicked = chartScale.GetValueByY(y);
var barId = ChartBars.GetBarIdxByX(ChartControl, x);
DebugPrint("Price clicked " + priceClicked);
DebugPrint("Bar Id clicked " + barId);
DebugPrint("Open Count " + Open.Count);
DebugPrint("High Count " + High.Count);
DebugPrint("Low Count " + Low.Count);
DebugPrint("Open " + Open[Open.Count - barId - 1]);
DebugPrint("High " + High[High.Count - barId - 1]);
DebugPrint("Low " + Low[Low.Count - barId - 1]);
}
catch (Exception ex)
{
DebugPrint("MouseLeftClicked - " + ex.Message + " - " + ex.StackTrace);
}
}
NinjaScript Output:
2024-09-21 20:29:00:848 - Price clicked -0.525274406332454
2024-09-21 20:29:00:848 - Bar Id clicked 1
2024-09-21 20:29:00:848 - Open Count 3
2024-09-21 20:29:00:848 - High Count 3
2024-09-21 20:29:00:848 - Low Count 3
2024-09-21 20:29:00:872 - MouseLeftClicked - 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.GetOpen(Int32 index)
at NinjaTrader.Data.Bars.GetOpen(Int32 index)
at NinjaTrader.NinjaScript.PriceSeries.get_Item(Int32 barsAgo)
(DebugPrint is my custom function)
Thanks

Comment